[fpc-pascal] Initializing Arrays?
Andrew Brunner
andrew.t.brunner at gmail.com
Thu Dec 25 18:46:06 CET 2008
I typically use Empty, SetSize, Copy, and IndexOf etc. Methods for all
my DataTyped Arrays. The SetSize method sets the size and for each
Item in the Array I call empty.
Empty(Var Item:TJSMContact); overload;
Empty(Var Items:TJSMContacts); overload;
var
iLcv:integer;
begin
For iLcv:=0 to High(Items) do
Empty(Items[iLcv]);
SetLength(Items,0);
end;
function SetSize(Var Items:TJSMContacts, Size:Integer):integer; overload;
var
iLength:Integer;
iLcv:integer;
begin
iLength:=Length(Items);
SetLength(Items,Size);
for iLcv:=iLength to Size do
Empty(Items[iLcv]);
end;
procedure Copy(Var Source,Destination:TJSMContact); overload;
begin
Desintation.Name:=Source.Name;
// etc
end;
On Thu, Dec 25, 2008 at 1:06 AM, Joseph Montanez
<jmontanez at gorilla3d.com> wrote:
> I've already read that its not built into pascal but how do I get around
> this? If I have:
>
> contacts : array [1 .. 256] of JSMContact;
>
> the only way to initialize it is?
>
> with contacts[1] do
> begin
> Name := '';
> PhoneNo := '';
> end;
>
> Also if I am passing a var to a procedure how would use a pointer as
> parameter?
>
> { Wont compile :( }
>
> procedure JSMContactAdd(contact : ^JSMContact);
>
> JSMContactAdd(@contacts[1]);
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list