🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #165

Re: how to pass a record to a component?

#165
From: ils
Date: Mon, 12 Mar 2007 10:50
55 lines
2742 bytes
On 8 ���, 19:31, Poetj...@gmail.com wrote:
> 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;

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
Technical Details
Message-ID: <1173696659.590230.309620@t69g2000cwt.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!t69g2000cwt.googlegroups.com!not-for-mail
References: <1173371463.152428.251530@s48g2000cws.googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 109d30,73f598ccbd7e07a3
X-Google-Attributes: gid109d30,public
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!t69g2000cwt.googlegroups.com!not-for-mail
From: "ils" <ilshat@gmail.com>
Newsgroups: borland.public.delphi.language.objectpascal
Subject: Re: how to pass a record to a component?
Date: 12 Mar 2007 03:50:59 -0700
Organization: http://groups.google.com
Lines: 56
Message-ID: <1173696659.590230.309620@t69g2000cwt.googlegroups.com>
References: <1173371463.152428.251530@s48g2000cws.googlegroups.com>
NNTP-Posting-Host: 82.204.130.100
Mime-Version: 1.0
Content-Type: text/plain; charset="koi8-r"
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1173696671 13131 127.0.0.1 (12 Mar 2007 10:51:11 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 12 Mar 2007 10:51:11 +0000 (UTC)
In-Reply-To: <1173371463.152428.251530@s48g2000cws.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 WSUS
Complaints-To: groups-abuse@google.com
Injection-Info: t69g2000cwt.googlegroups.com; posting-host=82.204.130.100;
   posting-account=IARNvQ0AAAA9TWrwrtZpP_mch3Nd_pj_