Solved

Problem in a Component derived from TClientDataSet using TStrings

Posted on 2009-05-15
7
374 Views
Last Modified: 2012-05-07
Hello ,

      I want to create a Custom Component based on the TClientDataset class. I want my new component to be able to hold some strings in a TstringList. I have used the same technique in some other components and worked fine. No when I am trying to open the TStrings Editor in the Object Inspector the following error message appears "Could not assign a nil to a TRichEditStrings". What may be wrong ?

Thank you in advance.
TMySecondClientDataset = class(TClientDataSet)
  private
    FFileGroups: TStrings;
  protected
    constructor Create(AOwner : TComponent);
    destructor Destroy;
  public
  published
    property FileGroups: TStrings read FFileGroups write FFileGroups;
  end;
 
constructor TMySecondClientDataset.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FFileGroups := TStringList.Create;
end;
 
destructor TMySecondClientDataset.Destroy;
begin
  FFileGroups.Free;
end;

Open in new window

0
Comment
Question by:ikaros23
  • 4
  • 3
7 Comments
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 250 total points
ID: 24393263
you need a setter to check for nil
type
  TMySecondClientDataset = class(TClientDataSet)
  private
    FFileGroups: TStrings;
    procedure SetFileGroups(const Value: TStrings);
  public
  published
    property FileGroups: TStrings read fFileGroups write SetFileGroups;
  end;
 
procedure TMySecondClientDataset.SetFileGroups(const Value: TStrings);
begin
  fFileGroups.BeginUpdate;
  try
    if Assigned(Value) then 
      fFileGroups.Assign(Value)
    else 
      fFileGroups.Clear;
  finally
    fFileGroups.EndUpdate;
  end;  
end;

Open in new window

0
 

Author Comment

by:ikaros23
ID: 24393331
I tried your solution but nothing happened :(. In another component that I have created (derived from TADOQuery) The same technique worked fine . Why would I need a setter procedure in this one ? I am very confused :( ......
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24393804
did you assign nil ?

you want to assign the content of the list ,
not the list itself
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

Author Closing Comment

by:ikaros23
ID: 31581831
Your setter procedure was right. What I though was right in the components I told you I have used the same technique proved to be wrong.I had written a property editor to access the strings . when I used the default the same error occurred. Although I have used a slightly different approach than the one you suggested (taken by FSQL property of ADOQuery) , I am accepting your solution , because its essentially the same. Thank you very much,
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24394614
but why then a B grade ?
0
 

Author Comment

by:ikaros23
ID: 24397948
Sorry for the B . I am new to the experts and placed a B by mistake ... SORRYYYY :(
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24400097
lol, no need to apologize, i was just wandering why ...
just follow the guide lines.
post a A, when accept,
post a B when you had to solve yourself and further investigation didn't help
post a C ... nobody likes this ...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.

790 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