Solved

assigning properties of component

Posted on 2000-03-18
10
241 Views
Last Modified: 2010-04-04
Dear experts!

I get a problem. The problem is that I do not know how to associate property of component and text value of property name.

For example. Let's suppose I have a text file. The text file look like this:
....
left = 100
top = 200
caption = "some caption"
...

Then I have a component (abstract component). How to assign values to property of the component from that text file?

It must be:

procedure AssignProp(aComp : TComponent; aPropName : string; aValue : Variant);
begin
  // implementation wanted!!!!
end;

PS:
------------
I know how to save/load a component to/from stream in the text format, it's unusable for me.
------------
if aPropName = 'LEFT' then aComp.Left := aValue; // is also unusable.

PPS:
I'm not hurry up.
0
Comment
Question by:ITugay
10 Comments
 

Expert Comment

by:HamidHossain
ID: 2631022
You can use TStringList


var
  List : TStringList;
begin
  try
    List := TStringList.Create;
    List.LoadFromFile('MyText.txt');
    aComp.Left := StrToInt(List.Values['Left']);
    ...
    ...
  finally
    List.Free;
  end;
end;
0
 

Expert Comment

by:HamidHossain
ID: 2631025
remember that

--- MyText ---
Fire=12
Caption=Welcome to my component
--------------

Can be accessed by

  MyInteger := IntToStr(List.Values['Fire']);
  MyString  := List.Values['Caption'];

and so on ...

Regards,
Hamid
0
 

Expert Comment

by:HamidHossain
ID: 2631026
take care for letters case
 so 'Fire' <> 'fire'

;)
0
 

Expert Comment

by:HamidHossain
ID: 2631029
I made misstake in the second comment

it should be StrToInt

Sorry
0
 
LVL 9

Author Comment

by:ITugay
ID: 2631040
Dear Hamid!

I can manipulate with TStrings and I have some understanding about characters case. I told about  an abstract component, it mean that component may have or may NOT have a property with name "Left".

Best regards,
Igor.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Expert Comment

by:inthe
ID: 2631074
Hi
do you know about readcomponentres / writecomponentres ?
They can save a entire form full of components or just one component (as long as the components properties are published )it saves to dfm.
you can then use convert.exe (in delphi bin dir )or i can give you procedure for comversions to convert the dfm writecomponentres makes into a text file.
 
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 2631152
0
 
LVL 9

Author Comment

by:ITugay
ID: 2631179
to inthe,
Of course, I know about his ;)
Igor.

PS: To all, I will available at mondey ;-)
0
 

Expert Comment

by:carlca
ID: 2632047
If you have Delphi 5, simply include TypInfo in your uses clause and use the SetPropInfo procedure. It is used in almost the same as your AssignProp procedure. The parameters are:

(Instance: TObject;
const PropName: string;
const Value: Variant);

Cheers,
Carl
0
 
LVL 9

Author Comment

by:ITugay
ID: 2633016
Thanx to Epsylon and Carl.

Yes, "TypeInfo" is magic word what I need. I found all I need in that unit.

Thanx all.

Igor.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now