You will need to allocate memory for holding "Data"
The "Data" will be lost as soon as it goes out of scope - ie the function finishes...
"Data" is just a local variable
 
 
Regards
Paul McKenzie
Analyst Programmer
SMSS Ltd.
----- Original Message -----
Sent: Monday, October 14, 2002 12:09 PM
Subject: RE: RE: [DUG]: Load different types from one procedure?

Sorry, that was just an example, no the types are completely different, I should have made this clear.

 

I’m not too good with pointers, but would the code below be correct for the implementation.

 

function LoadTemplate(Path: String): Pointer;

var

  Stream: TFileStream;

  Data: array[0..43450] of char;

begin

  Stream := nil;

  FillChar(Data, Sizeof(Data), #00);

 

  Stream := TFileStream.Create(Path, fmOpenRead or fmShareDenyWrite);

  Stream.Position := 0;

  Stream.Read(Data, Stream.Size);

 

  ClearStyle(Result);

  ShowMessage(strCantReadDat + MyStylesPath + strExists);

 

  Result := @Data;

  Stream.Free;

end;

 

 

and use it like:

 

MyTemplate := TTemplate(LoadTemplate(Path)^);

 

As I said this may not be correct, but Ive never really used pointers before.

 

Jason

 

 

-----Original Message-----
From: Andreas Toth [mailto:[EMAIL PROTECTED]]
Sent: Monday, 14 October 2002 11:14 a.m.
To: Multiple recipients of list delphi
Subject: RE: [DUG]: Load different types from one procedure?

 

I don't like the sound of using the path as an indicator of how the data is to be interpreted. A better solution would be to pass in a third parameter which defines the way the data is to be interpreted, i.e., the record to use.

 

By the way, depending on how much control you have over the data, I would really try to do away with one of the records, since. after all, they describe the same same information, just in a different order. Is this really necessary?

 

 

-Andreas

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Jason Coley
Sent: Monday, 14 October 2002 10:29
To: Multiple recipients of list delphi
Subject: [DUG]: Load different types from one procedure?

Is there a way I can load different record type objects using one procedure?

 

I have

 

TType1 = record

            intone: integer;

            strone: array[1..49] of char;

end;

 

TType2 = record

            strtwo: array[1..49] of char;

            Inttwo: integer;

end;

 

These types are stored as files on my system, but I want to have one procedure/function that can load either type by simply passing the path, can you do this.

 

I have something like

 

Procedure LoadTemplate(Path: String; var Data: array of char);

 

But this doesn’t work as the type and array are not compatible.

 

I think this could be a Monday morning thing, but I have had two coffee’s!!!!

 

Jason

Reply via email to