Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change property values (RTTI) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Oct-02
Category
Object Pascal
Language
Delphi 2.x
Views
100
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I use setpropvalue() function to set property values. It works fine if I set 
properties that are on first level (i.e.. button1.caption, button1.name,..), but it 
fails if I want to set properties like button1.font.name or radiogroup.items.text.

Answer:

1   function GetProperty(AControl: TPersistent; AProperty: string): PPropInfo;
2   var
3     i: Integer;
4     props: PPropList;
5     typeData: PTypeData;
6   begin
7     Result := nil;
8     if (AControl = nil) or (AControl.ClassInfo = nil) then
9       Exit;
10    typeData := GetTypeData(AControl.ClassInfo);
11    if (typeData = nil) or (typeData^.PropCount = 0) then
12      Exit;
13    GetMem(props, typeData^.PropCount * SizeOf(Pointer));
14    try
15      GetPropInfos(AControl.ClassInfo, props);
16      for i := 0 to typeData^.PropCount - 1 do
17      begin
18        with Props^[i]^ do
19          if (Name = AProperty) then
20            result := Props^[i];
21      end;
22    finally
23      FreeMem(props);
24    end;
25  end;
26  
27  procedure TForm1.Button1Click(Sender: TObject);
28  var
29    propInfo: PPropInfo;
30  begin
31    PropInfo := GetProperty(Button1.Font, 'Name');
32    if PropInfo <> nil then
33      SetStrProp(Button1.Font, PropInfo, 'Arial');
34  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC