Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to pass a record to a component?

3 views
Skip to first unread message

Poet...@gmail.com

unread,
Mar 8, 2007, 11:31:03 AM3/8/07
to
hi, i have a question,
if i try to run the following code i get the error "Left side cannot
be assigned to".
i understand that this has something to do with the usage of TypeA.
My question is, how can you pass records to components? because,
apparently, the following approach does not work.

thank you all in advance,

Type TypeA=record
some_int:integer;
some_real:real;
end;

Type TypeB = class(TComponent)
private
PrivateA: array of TypeA;
function GetA(index:integer):TypeA;
procedure SetA(index:integer;value:TypeA);

public
procedure SetLengthA(i:integer);
property A[i:integer]:TypeA read GetA write SetA;
end;

procedure TypeB.SetLengthA(i:integer);
begin
setlength(PrivateA,i);
end;

function TypeB.GetA(index:integer):TypeA;
begin
result:=PrivateA[index];
end;

procedure TypeB.SetA(index:integer;value:TypeA);
begin
PrivateA[index]:=value;
end;

procedure TForm1.Button1Click(Sender: TObject);
var B: TypeB;
begin
B:=TypeB.create(nil);
B.SetLengthA(3);
B.A[1].some_int:=5; // <----------- this causes the error !
end;

ils

unread,
Mar 12, 2007, 6:50:59 AM3/12/07
to

1. use pointer to record TTypeA like
type
PTypeA = ^TTypeA;

2. use "array of PTypeA" instead of "array of TTypeA"
3. don't forget to allocate memory for all elements of that array

0 new messages