Recent

Author Topic: Should TMemo have property FileName: String?  (Read 17542 times)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Should TMemo have property FileName: String?
« on: July 23, 2012, 02:38:30 pm »
I am using an Array of TMemo and keeping track of the FileName for each TMemo became a problem.  So I extended TMemo with property FileName: String.  Problem solved. 

Extending it is easy, but shouldn't this property already be part of TMemo to begin with?  I haven't checked TSynEdit but I would think the same would apply there as well.  Any thoughts?
Lazarus Trunk / fpc 2.6.2 / Win32

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Should TMemo have property FileName: String?
« Reply #1 on: July 23, 2012, 02:50:09 pm »
Quote
but I would think the same would apply there as well.  Any thoughts?

I'd say no,  a TMemo is just that.  It can get it's data from anywhere, eg. TDbMemo/registry etc.
You might say if you don't use it, then you can ignore it.  Problem here is that on a 64bit machine that's wasted 8 bytes for something you don't use.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Should TMemo have property FileName: String?
« Reply #2 on: July 23, 2012, 04:15:11 pm »
Hi KpjComp :)  I might agree with that if it weren't for the fact that there are already countless properties that are either very rarely used or can not be used throughout Lazarus.  It seems like almost every component has something like that.  Just a quick look at TMemo and I see 'PasswordChar'.  I can't believe that is used very often in TMemo.  There is also 'AutoSize' which at first glance seems to do nothing in TMemo.
« Last Edit: July 23, 2012, 04:16:57 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Should TMemo have property FileName: String?
« Reply #3 on: July 23, 2012, 04:43:13 pm »
Quote
Hi KpjComp   I might agree with that if it weren't for the fact

Hi Avishai, 

We have a saying in this country -> Two wrongs don't make a right.

Unfortunately it's one of the problems of Single inheritance object model.
Multi-Inheritance might have been a good solution but unfortunately such concepts were deemed evil and never came to pascal, one nice thing of C++.

Maybe smart linking can help here, but I'm not sure to what level smart linking can go.  Removing Class private vars seems like it might be pretty hard for the compiler to optimize out.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: Should TMemo have property FileName: String?
« Reply #4 on: July 23, 2012, 04:44:48 pm »
The idea is that TMemo IS a textarea component ... if you want create a new class with this property ...
if i store a result from ajax call it must have a url property also?

and another hint to no create a array of memos ... use array of TStrings 
Speak postscript or die!
Translate to pdf and live!

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Should TMemo have property FileName: String?
« Reply #5 on: July 23, 2012, 04:53:56 pm »
Thanks Blestan, but I need the TMemo in this app.  It is just a very basic text editor with TPageControl and a TMemo on each TabSheet.  So I need an Array of TMemo.

I started with just one TMemo and an Array of TStringList.  For each Tabsheet, I just changed the Parent of the TMemo, stored the Text in a TStringList... But it got much too complicated for such a simple app and the memory savings were tiny.
Lazarus Trunk / fpc 2.6.2 / Win32

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Should TMemo have property FileName: String?
« Reply #6 on: July 23, 2012, 04:58:02 pm »
@Avishai.

There is a little trick you can do to give you extra properties.

If you define say another unit called StdCtrls2, and you make sure this unit comes after the default stdCtrls you can extend at runtime extra properties fields you can see from the TMemo.  The advantage here is you don't need to create say a TMyMemo and register it, or create these TMyMemo at runtime, all your designtime TMemo's will get this extra property.

eg.
Code: [Select]
unit stdctrls2;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, stdCtrls;

type
  TMemo = class(stdCtrls.TMemo)
  public
    filename:string;
  end;

implementation

end.   

It's a bit like a class helper, but class helpers don't allow extra variables, only methods etc.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Should TMemo have property FileName: String?
« Reply #7 on: July 23, 2012, 05:09:50 pm »
Thanks KpjComp!  I din't know that one.  I'm not even going to ask how you learned this :)  It works perfectly.
Lazarus Trunk / fpc 2.6.2 / Win32

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Should TMemo have property FileName: String?
« Reply #8 on: July 23, 2012, 05:13:30 pm »
Are you sure that works?

If you tested it in a sample project, then yes it may seem to work. BUT...

IRC the lfm reader has still a reference to StdCtrls.TMemo. So when reading the LFM, that is created, and memory allocation only gets memory for that.

If you access the extra field, you would (If I am right) access unallocated memory.
That wouldn't immediately cause an error, so it may SEEM to work at first.
But if you have other objects, then you may overwrite them....


It may work, if your app registers the new TMemo with the reader (there is a function to do this). But I have not tested this.
And I certainly do not recommend it.


---------
Besides "Array of TMemo"  is not read from LFM? So you could do TMyMemo?

If you do not want to create a TMyMemo, then instead of
   Array of TMemo

do
  Array of Record
    Memo: TMyMemo;
    FileName: string;
  end;

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Should TMemo have property FileName: String?
« Reply #9 on: July 23, 2012, 05:20:51 pm »
Thanks Martin_fr.  I'll have to do some more testing of course, but I hope it works out.  It's just too cool not to want to see it work :)

But the original question was whether 'FileName' should be a property of TMemo.  I'm not saying that it should be.  I'm just asking for opinions.  To me it seems logical, but there are always other things to consider.

So far I have 1 vote for NO.
« Last Edit: July 23, 2012, 05:29:09 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Should TMemo have property FileName: String?
« Reply #10 on: July 23, 2012, 05:21:26 pm »
Hi Martin_fr,

No, it does actually create your customized instance of TMemo.

eg.
Code: [Select]
constructor TMemo.Create(AOwner:Tcomponent);
begin
  inherited Create(AOwner);
  showmessage('my instance created');
end;   

The above showmessage will get called.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Should TMemo have property FileName: String?
« Reply #11 on: July 23, 2012, 06:04:53 pm »
But the original question was whether 'FileName' should be a property of TMemo.  I'm not saying that it should be.  I'm just asking for opinions.  To me it seems logical, but there are always other things to consider.

So far I have 1 vote for NO.
Ok, you're asking for it... Another vote for NO.


Of course, you could always raise a bug report with a patch... after all, regardless of our opinions, the Lazarus committers get to decide.
Don't know about the chances of the patch getting in... but if it is that important for you, you can always try.

Regards,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Should TMemo have property FileName: String?
« Reply #12 on: July 23, 2012, 06:13:24 pm »
Thanks BigChimp.  That's why I asked the question.  I don't want to go to BugTracker and ask for something that most people don't see a need for.  I think they have enough to do as it is.  And I appreciate your response.
Lazarus Trunk / fpc 2.6.2 / Win32

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Should TMemo have property FileName: String?
« Reply #13 on: July 23, 2012, 06:17:57 pm »
Avishai, I think this shows you're a very considerate person. I'd say there's nothing wrong with posting the patch and seeing what happens... but I commend you for your tact and diplomatic skills.

(Some issue tracker requests are very vague and I think[1] the devs would have a lot of work. In this case, I think it's a simple decision if you give all the details. If you provide a patch as well, there wouldn't be much work involved in implementing it as well.)

[1] Not a Lazarus/FPC dev myself, just a compulsive issue/patch submitter, so can only guess ;)

Regards,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Should TMemo have property FileName: String?
« Reply #14 on: July 23, 2012, 06:28:15 pm »
Thanks BigChimp, but so far I seem to be the only person that thinks it 'might' be a good idea, and I have a solution without it so I think I'll wait see if there are any other comments.

I have seen some of the 'Feature Requests' on Bugtracker.  Some of them are, well, strange.
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018