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 set a string or integer property for a component if it exists 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
30-Aug-02
Category
Object Pascal
Language
Delphi 2.x
Views
125
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I am building a routine that checks our forms for validity before deploying them. I 
would like to use some kind of structure that tests if a component type has access 
to a certain property, something like: " if (self.Controls[b] has Tag) then ...". 
Can anyone offer suggestions?

Answer:

Here's an example of setting a string property for a component if it exists and 
another for an integer property:

1   procedure SetStringPropertyIfExists(AComp: TComponent; APropName: string;
2     AValue: string);
3   var
4     PropInfo: PPropInfo;
5     TK: TTypeKind;
6   begin
7     PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
8     if PropInfo <> nil then
9     begin
10      TK := PropInfo^.PropType^.Kind;
11      if (TK = tkString) or (TK = tkLString) or (TK = tkWString) then
12        SetStrProp(AComp, PropInfo, AValue);
13    end;
14  end;
15  
16  procedure SetIntegerPropertyIfExists(AComp: TComponent; APropName: string;
17    AValue: Integer);
18  var
19    PropInfo: PPropInfo;
20  begin
21    PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
22    if PropInfo <> nil then
23    begin
24      if PropInfo^.PropType^.Kind = tkInteger then
25        SetOrdProp(AComp, PropInfo, AValue);
26    end;
27  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