Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

assigning properties of component

Posted on 2000-03-18
10
243 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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