Solved

Problem in a Component derived from TClientDataSet using TStrings

Posted on 2009-05-15
7
373 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 96
Export Table to CSV - Access to CSV - using python 18 138
how can i search if string exist in array ? 3 59
Twebbrowser add css to the header 3 25
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

809 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