Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Tlist Problem/question..


  • Please log in to reply
5 replies to this topic

#1 gogetax1

gogetax1

    CC Newcomer

  • Member
  • PipPip
  • 16 posts

Posted 28 May 2012 - 10:36 AM

hey guys.. i will explain this quick..

i want to put into a TList (or any other kind of list) a type record. but it doesnt work for me..

example:

type TMyType=record
MyVar:Integer;
end;

var
V :=TMyType;
S:TList;
begin
S := TList.Create;
V.MyVar := 100;
s.add(V@);

V.MyVar := 500;
s.add(V@);

V := TMyType(S[0]^);
Showmessage('Number is: '+IntToStr(V.MyVar));


where do i go wrong with this?
  • 0

#2 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 28 May 2012 - 11:02 AM

I dont know if this is a typo, but
s.add(V@);

will not compile. I think you meant this:
s.add(@V);

Beside the "typo" above, I can not see anything wrong with the code. I mean it should compile and you still get ShowMessage dialog showing "500". However what you were doing in the sample code was just adding variable V twice to the TList. So,
V.MyVar := 500;
will overwrite
V.MyVar := 100;
. Therefore whether you are using S[0] or S[1], you will still get the same value, since both are pointing to the same memory location.
  • 0

#3 gogetax1

gogetax1

    CC Newcomer

  • Member
  • PipPip
  • 16 posts

Posted 28 May 2012 - 11:35 AM

s.add(@V);
this wont compile

only s.add(v@) compiles..
  • 0

#4 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 29 May 2012 - 08:30 PM

s.add(@V);
this wont compile

only s.add(v@) compiles..


Then you definitely are not using Delphi. What compiler are you using?
  • 0

#5 gogetax1

gogetax1

    CC Newcomer

  • Member
  • PipPip
  • 16 posts

Posted 30 May 2012 - 06:52 AM

Embarcadero XE2 - Delphi.
  • 0

#6 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 08 June 2012 - 09:41 PM

only s.add(v@) compiles..


Nope. That definite won't compile in any version of Delphi. See this page on official Embarcadero's wiki page on pointers.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download