Solved

Problem in a Component derived from TClientDataSet using TStrings

Posted on 2009-05-15
7
372 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 36

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 36

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 Trending Threat Insights Every Day

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.

 

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 36

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 36

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Enhanced For loop vs ForEach Loop 4 56
Specific format 21 140
mapShare challenge 13 68
How does Google get such fast response times? 5 122
This article will show, step by step, how to integrate R code into a R Sweave document
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.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

19 Experts available now in Live!

Get 1:1 Help Now