Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 21-02-2015
JuanOrtega JuanOrtega is offline
Miembro
NULL
 
Registrado: sep 2011
Posts: 130
Poder: 13
JuanOrtega Va por buen camino
Crear array of char con valores predeterminados

Hola tengo un problema con este codigo :

Código Delphi [-]
function hola(texto:string):bool;
var
  test: string;
  probando: Array [0 .. Length(texto)  + 7] of Char;

Como ven estoy tratando de crear una array of char con la longitud de la variable string que se usa como parametro en la funcion pero el problema es que siempre me dice que la variable texto no existe , probe volviendo a declarar la variable despues del begin pero no me deja me dice que no se esperaba el array.

¿ como logro este ejercicio ?
Responder Con Cita
  #2  
Antiguo 21-02-2015
Avatar de BDWONG
BDWONG BDWONG is offline
Miembro
NULL
 
Registrado: nov 2013
Posts: 113
Poder: 11
BDWONG Va por buen camino
Tienes que usar arreglos dinamicos y asi podras establecer el tamaño segun el caso especifico
te dejo esto haber si te sirve


Código Delphi [-]
function funcion(texto:string):boolean;
var
  probando: Array of Char;
begin

    SetLength(probando,length(texto)+7);
    writeln('Tamano del arreglo ',length(probando));

    result:=true;
end;

begin

  writeln(funcion('cadena'));
  readln;
end.

saludos.......
Responder Con Cita
  #3  
Antiguo 21-02-2015
JuanOrtega JuanOrtega is offline
Miembro
NULL
 
Registrado: sep 2011
Posts: 130
Poder: 13
JuanOrtega Va por buen camino
te agredezco la ayuda , una pregunta sobre el codigo , el cero en "0.." ¿ ya no importa y o es el mismo resultado ?

avance en el codigo :

Código Delphi [-]
function hola(texto:string):bool;
var
  test: string;
  probando: Array of Char;
bein
  SetLength(probando, length(texto) + 7);
  test := 'hola mundo';
  StrCopy(probando, pchar(test));
end;

pero ahora me da este error que antes no me daba : "There is no overloaded version of 'StrCopy' that can be called with these arguments" , ¿ a que se debe ?

Última edición por JuanOrtega fecha: 21-02-2015 a las 22:19:18.
Responder Con Cita
  #4  
Antiguo 21-02-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Lepuke.

No entiendo el sentido del código, pero si como estimo, deseas pasar el contenido del string al array of Char, deberías hacer:
Código Delphi [-]
...
  test := 'hola mundo';
  StrPCopy(@probando[1], test); // o también: StrPCopy(Addr(probando[1]), test);
...

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #5  
Antiguo 22-02-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Lepuke,

Cita:
Empezado por Lepuke
...Crear array of char con valores predeterminados...


Revisa este código:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
   ArrName : Array of Char;
   Name : String;
   AuxName : String;
   i : Integer;

begin

   Name := 'Nelson Garcia';

   SetLength(ArrName,Length(Name));
   StrPCopy(@ArrName[0],Name);
   Showmessage('ArrName: ' + String(@ArrName[0]));

   AuxName := String(@ArrName[0]);
   Showmessage('AuxName: ' + AuxName);

   AuxName := EmptyStr;
   for i := Low(ArrName) to High(ArrName) do
      AuxName := AuxName + ArrName[i];
   Showmessage('AuxName: ' + AuxName);

   Finalize(ArrName);

end;
El código anterior en Delphi 7 sobre Windows 7 Professional x32, ejemplifica el uso de arreglos dinámicos de tipo Char.

Espero sea útil

Nelson.
Responder Con Cita
  #6  
Antiguo 20-08-2015
JuanOrtega JuanOrtega is offline
Miembro
NULL
 
Registrado: sep 2011
Posts: 130
Poder: 13
JuanOrtega Va por buen camino
gracias por la ayuda , tengo un duda sobre el mismo tema , si en vez de que sea un Array of Char sea un Array of Byte ¿ como seria para agregarles varios elementos ? , intente con los ejemplos que me dieron y siempre me devuelve el mismo error :

There is no overloaded version of 'StrPCopy' that can be called with these arguments

Última edición por JuanOrtega fecha: 20-08-2015 a las 20:29:09.
Responder Con Cita
  #7  
Antiguo 20-08-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Lepuke,

Cita:
Empezado por Lepuke
...si en vez de que sea un Array of Char sea un Array of Byte ¿como seria para agregarles varios elementos?...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
   Max = 10;

var
   A1 : Array of Byte;
   i : Integer;

begin

   for i := 1 to Max do
   begin
      SetLength(A1,Length(A1)+1);
      A1[High(A1)] := i;
   end;

   for i := Low(A1) to High(A1) do
      MessageBox(0, PChar(Format('A1[%d] = %d',[i,A1[i]])) , 'Dynamic Arrays', MB_OK);

   Finalize(A1);   

end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, ejemplifica el uso de arreglos dinámicos de tipo Byte.

Espero sea útil

Nelson.
Responder Con Cita
  #8  
Antiguo 21-08-2015
JuanOrtega JuanOrtega is offline
Miembro
NULL
 
Registrado: sep 2011
Posts: 130
Poder: 13
JuanOrtega Va por buen camino
era el ejemplo que buscaba , gracias por la ayuda nlsgarcia.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
array of char en delphi xe look OOP 2 09-04-2014 02:55:31
convertir arreglo Array[0..33] of Char; a cadena richy08 OOP 9 17-02-2012 21:20:04
Duda convertir de int a char array mizzard C++ Builder 3 17-04-2011 12:14:47
Cargar array of char de un archivo binario JosepZ Varios 9 13-11-2007 00:28:16
Valores predeterminados en firebird 1.5 ronimaxh Firebird e Interbase 5 20-09-2005 10:48:57


La franja horaria es GMT +2. Ahora son las 10:29:20.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi