Link to home
Start Free TrialLog in
Avatar of Tomas Helgi Johannsson
Tomas Helgi JohannssonFlag for Iceland

asked on

Problem with propertyeditor (Need help ASAP)

Hi!

I'm having some trouble with a PropertyEditor in a component that I'm writing.
The code (or at least the same structure ;)
------
type
 TMyForm = class(TForm);
    slAF : TStringList;
    slBF : TStringList;
    ....
 end;
 TC = class;
 TA = class(TComponent)
     ...    
     procedure DoStuff;
   private
     FC : TC;
     slA : TStringList;
     slB : TStringList;
   public
     constructor Create;
     destructor  Destroy; override;
   published
     property pFC : TC read FC;
   end;
 TC = class
     FA : TA;
     procedure Add(a,b : String);
 end;
 TB = class(TPropertyEditor)
   function GetAttributes : TPropertyAttributes; override;
   procedure Edit;override;
 end;
 
 implementation
 
 constructor TA.Create(AOwner : TComponent);
 begin
    inherited Create(AOwner);
    FC := TC.Create;
    FC.FA := Self;
    slA := TStringList.Create;
    slB := TStringList.Create;
 end;
 
 destructor TA.Destroy;
 begin
    FC.Free;
    slA.Free;
    slB.Free;
    inherited Destroy;
 end;

 procedure TA.DoStuff;
 begin
   // DO stuff with data in slA and slB.
 end;
 
 procedure TC.Add(a,b : String);
 begin
      FA.slA.Add(a);
      FA.slB.Add(b);
 end;
 
 function TB.GetAttributes: TPropertyAttributes;
 begin
      Result := [paDialog];
 end;
 
 procedure TB.Edit;
 var
    myForm : TMyForm;
    xC : TC;
    i : Integer;
 begin
    myForm := TMyForm.Create(self);
    try
         xC := TC(GetComponent(0));
         myForm.slA.Assign(xC.slA);
         myForm.slA.Assign(xC.slB);
         if myForm.ShowModal = mrOK then
         begin
           xC.slA.Clear;
           xC.slB.Clear
           for i := 0 to myForm.slA.Count -1 do
               xC.slA.Add(myForm.slA[i]);
           for i := 0 to myForm.slB.Count -1 do
              xC.slB.Add(myForm.slB[i]);
         end;
    finally
         myForm.Free;
    end;
 end;

----
In the register procedure I register TA and TB. TB is assigned to TC.
The problem is that I can see the last entered data that in the form every time I click on the property FC in the object inspector. But the procedure DoStuff cant see the data when I run the program and call the procedure. But if
I call the procedure TA.pFC.Add('A data','More data') and then call DoStuff the component sees the two strings that I added before. Why ???
What am I doing wrong ???
Am I forgetting something ???

Regards,
  Tomas Helgi
Avatar of nestorua
nestorua

HI,
DELPHI doesn't know how to srite and read your property's
data to the Stream.
You must define DefineProperties, DefineProperty methods
in your component to teach DELPHI storing your data.
Sincerely,
Nestorua.
ASKER CERTIFIED SOLUTION
Avatar of DelphiArchitect
DelphiArchitect

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tomas Helgi Johannsson

ASKER

Hi James!

I have created a functions to read and write the pFC property. That didn't help.
What dostuff function does is simply to show me the size of slA and slB and the first 4 strings in each.
I have implemented the DefineProperties function and the other functions to read and write but I keep getting the same results as before. :(
How can I write to the correct dynamically created component ? My methods seems to not work. ;) :(
Maybe I'm forgetting something ??

Regards,
Tomas Helgi
TomasHelgi:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
TomasHelgi,
No comment has been added lately (17 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: delete / Point Refund
-- Please DO NOT accept this comment as an answer ! --

Thanks,

knightmad
EE Cleanup Volunteer

P.S. Remember you can object this recommendation, but do it as fast
as you can, because it will be probably cleaned in about 7 days.