Jump to content


Photo

Add Enhancement


  • Please log in to reply
5 replies to this topic

#1 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 28 February 2008 - 01:27 PM

Hi Boki,

Could you add the following feature to controls using TStrings as text storage?

A procedure Add(const aFormat: string; const aArgs: array of const) function that looks like

CODE
procedure Add (const aFormat: string; const aArgs: array of const);
begin
  Lines.Add(Format(aFormat, aArgs));
end;


Not instead of the Lines.Add function but directy on the object, so it can be called like:

CODE
NxMemo1.Add('%2.2d - %s',[line,s]);


It would also be handy in TCells as an addition to AsString to have a similair AsFormat procedure besides the properties.
G.W. van der Vegt

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,580 posts
  • Gender:Male

Posted 28 February 2008 - 07:08 PM

Hello Wim,

I will add it. Can you please only tell me what will be better:

1) Adding this procedure to every control (such as NxMemo), or
2) Inheriting own class like TNxStrings = class(TStrings) and adding this method. Then change TStrings inside components with it with TNxStrings.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 29 February 2008 - 02:49 PM

Hi Boki,

Difficult question.

It depends a bit on wether you want to enhance the TStrings more and/or want to go for Unicode ones in the future.

For consitency it would be nice to overload existing methods in TStrings so option 2. For shorter code option 1 would be better and you would keep the original TStrings as they are.

If you intent to do more enhancements I certainly would go for 2) and subclass TStrings. For possible enhancements you could also have a look at TStringList (I always use those).

You would have to make the TNxStrings public too so it's accessible as a class on it own.

Enhancements I could imagine are:
  • Delete with a Start/End parameter (to delete more than one line at once).
  • Easy Image support using Object underneath so you can have logging fields where each line has a image in column 0.
  • Support for Virtual text (where you have to supply it in en event handler when needed)
  • Sorting on Names and or Values
  • Etc.

Privately for example I enhanced the TIniFile this way to make Read/WriteFloat more resistant to decimal separator changes and unified support for memory inifiles, diskbased ones, application one (autonaming) and external ones. And I'm quite happy with it.

QUOTE (Boki (Berg) @ Feb 28 2008, 07:08 PM) <{POST_SNAPBACK}>
Hello Wim,

I will add it. Can you please only tell me what will be better:

1) Adding this procedure to every control (such as NxMemo), or
2) Inheriting own class like TNxStrings = class(TStrings) and adding this method. Then change TStrings inside components with it with TNxStrings.

Best regards

G.W. van der Vegt

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,580 posts
  • Gender:Male

Posted 29 February 2008 - 03:08 PM

Hello Wim,

Maybe I can go with 2nd option. In my controls I am declaring properties as TStrings and then create TStringList inside .Create constructor.

In NxClasses.pas I already have next code:

CODE
{$IFDEF TNTUNICODE}
  TChar = WideChar;
  TString = WideString;
  TNxStrings = TTntStrings;
  TNxStringList = TTntStringList;
  TNxEditControl = class(TTntCustomEdit);
{$ELSE}
  TChar = Char;
  TString = string;
  TNxStrings = TStrings;
  TNxStringList = TStringList;
  TNxEditControl = TCustomEdit;
{$ENDIF}


Maybe this is a good place to expand TNxStrings smile.gif

PS. There is a one small problem for TNxMemo. Because here I inherit TCustomMemo (which already define Lines proeprty), only easy solution for this component is 1st. For this component I have add your code as:

CODE
procedure TNxMemo.Add(const AFormat: string; const Args: array of const);
begin
  Lines.Add(Format(AFormat, Args));
end;


Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 29 February 2008 - 03:51 PM

Hi Boki,

Some remarks:

1) Is TNT still a good way to go for UniCode? As it has been taken over (and moved out of PD) it's not maintained anymore as far as I know.

For WideString support there is also Mike Liscke's UniCode library which is still maintained.

2) This compiles (not sure it works properly). In the Create you could do inherited and then throw away the FLines and create a new one..

CODE
  TNxMemo1 = class(TCustomMemo)
    FLines: TStringList;
  private
    procedure SetLines(const Value: TStringList);
  public
    constructor Create(AOwner: TComponent); override;
    property Lines: TStringList read FLines write SetLines;
  end;

procedure TForm1.NxButton3Click(Sender: TObject);
var
  m2                            : TNxMemo1;
begin
  m2 := TNxMemo1.Create(Self);
  m2.Lines.Add('test');

  OutputDebugString(PChar(m2.FLines.Text));
end;

constructor TNxMemo1.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  if Assigned(FLines) then                //always nil as inherited Create sets the original FLines...
    begin
      OutputDebugString(PChar(string(FLines.ClassName)));
      FLines.Free;
    end;

  FLines := TStringList.Create;
  OutputDebugString(PChar(string(FLines.ClassName)));
end;


Btw the Lines of a TMemo is a TMemoStrings which is a TStrings Descendant.

QUOTE (Boki (Berg) @ Feb 29 2008, 03:08 PM) <{POST_SNAPBACK}>
Hello Wim,

Maybe I can go with 2nd option. In my controls I am declaring properties as TStrings and then create TStringList inside .Create constructor.

In NxClasses.pas I already have next code:

CODE
{$IFDEF TNTUNICODE}
  TChar = WideChar;
  TString = WideString;
  TNxStrings = TTntStrings;
  TNxStringList = TTntStringList;
  TNxEditControl = class(TTntCustomEdit);
{$ELSE}
  TChar = Char;
  TString = string;
  TNxStrings = TStrings;
  TNxStringList = TStringList;
  TNxEditControl = TCustomEdit;
{$ENDIF}


Maybe this is a good place to expand TNxStrings smile.gif

PS. There is a one small problem for TNxMemo. Because here I inherit TCustomMemo (which already define Lines proeprty), only easy solution for this component is 1st. For this component I have add your code as:

CODE
procedure TNxMemo.Add(const AFormat: string; const Args: array of const);
begin
  Lines.Add(Format(AFormat, Args));
end;


Best regards

G.W. van der Vegt

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,580 posts
  • Gender:Male

Posted 02 March 2008 - 11:59 PM

Hello Wim,

Please sorry for small delay.

I will need to take a deep thinking about this. I will most like to create my own class with WideString's but unfortunatelly TStrings class all have defined in string type sad.gif

I have add this function into NxMemo, but need to think about additionall steps more smile.gif

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users