Recent

Author Topic: [SOLVED] Why can't I overwrite?  (Read 694 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1592
[SOLVED] Why can't I overwrite?
« on: April 01, 2025, 11:48:45 am »
Hello,

I've used the attached approach to display multiple lines in a cell of Grid/ValueListEditor. My original application has no problem in running. But I cannot make a separate application (to check other things). TValueListEditor methods are redefined in unit2, and are used in unit1. The ValueListEditor should disdplay in multiple lines if a text in one cell gets long, but it doesn't. What am I missing?
« Last Edit: April 02, 2025, 12:54:35 pm by egsuh »

Thaddy

  • Hero Member
  • *****
  • Posts: 16773
  • Ceterum censeo Trump esse delendam
Re: Why can't I overwrite?
« Reply #1 on: April 01, 2025, 12:30:57 pm »
If you do not put the cell in edit mode (duh) you can't edit it?
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

egsuh

  • Hero Member
  • *****
  • Posts: 1592
Re: Why can't I overwrite?
« Reply #2 on: April 01, 2025, 03:04:03 pm »
Don’t be silly.

BrunoK

  • Hero Member
  • *****
  • Posts: 696
  • Retired programmer
Re: Why can't I overwrite?
« Reply #3 on: April 01, 2025, 03:31:29 pm »
Basically, you are writing a new component derived from a standard one.

See comments after code snippets.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.    Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ValEdit,
  9.    Unit2;
  10.  
  11. type
  12.  
  13.    { TForm1 }
  14.  
  15.    TForm1 = class(TForm)
  16.       procedure FormCreate(Sender: TObject);
  17.    private
  18.       VLE : Unit2.TValueListEditor;
  19.    end;
  20.  
  21. var
  22.    Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TForm1 }
  29.  
  30. procedure TForm1.FormCreate(Sender: TObject);
  31. begin
  32.    VLE := Unit2.TValueListEditor.Create(self);
  33.    VLE.parent := self;
  34.    VLE.align := alClient;
  35. end;
  36.  
  37. { TForm1 }
  38.  
  39. end.
You must reference the class you create with a unit qualifier matching the class where your new designed control is coded, at least in the .Create at line 32.
You would be better off defining a different descendant class name for your new class, such as maybe TValueListEdEgsuh(TValueListEditor), thus disambiguating instances types.

Then see attached unit2 for a very raw and basic beginning of implementing the new descendant control class, controlling the InplaceEdit will request some efforts.

Some points to note :
1 - NEVER write on the canvas outside a paint event as controlled by the WinControl and LCLCode.

2 - Use override for the methods you wish to implement to you liking. Try to take into account that methods in the ancestor frequently have most of the things you want to accomplish.

3 - When overriding methods, do not forget (most of the time) to call the inherited method you complemented, either at the beginning or at the end of your new method.

4 - The override method qualifier is very important. This qualifier drives the compiler to generate code that calls your enhanced method instead of that a referenced in the parent class. That leaves your method execute even if called in an ancestor class method.

5 - You'll quickly notice that using HeaderSizing to drive RowHeight sizing is not the right thing to do. That you have to calculate the rows height on a cell by cell basis that will be subsequently uses in the DrawCellText method call of your control.

6- Etc, etc...

Writing visual controls is a non trivial activity and I have quite a lot of respect for the guys who do it.

Thaddy

  • Hero Member
  • *****
  • Posts: 16773
  • Ceterum censeo Trump esse delendam
Re: Why can't I overwrite?
« Reply #4 on: April 01, 2025, 04:00:09 pm »
Don’t be silly.
That is not silly, I am right. Fix it.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

rvk

  • Hero Member
  • *****
  • Posts: 6703
Re: Why can't I overwrite?
« Reply #5 on: April 01, 2025, 04:18:18 pm »
You are defining procedure EditingDone; in private...
But... you don't use override or anything. So when do you think EditingDone is actually executed?

Putting override after that definition will fix it and your procedure EditingDone will be called.
It won't do what you expect (because there is also another WMPAINT procedure etc) but at least you are a step closer  :P

(You probably also want to override the DefaultDrawCell or something)
« Last Edit: April 01, 2025, 04:20:59 pm by rvk »

egsuh

  • Hero Member
  • *****
  • Posts: 1592
Re: Why can't I overwrite?
« Reply #6 on: April 02, 2025, 12:54:08 pm »
Quote
But... you don't use override or anything. So when do you think EditingDone is actually executed?

You are right. I redefined as follows and then it works. Thank you very much.

Code: Pascal  [Select][+][-]
  1.   TValueListEditor = class(ValEdit.TValueListeditor)
  2.    protected
  3.       procedure DoPrepareCanvas(aCol, aRow: Integer; aState: TGridDrawState);  override;
  4.       procedure EditingDone; override;
  5.       procedure HeaderSizing(const IsColumn: Boolean; const AIndex,
  6.          ASize: Integer); override;
  7.       procedure KeyPress(var Key: Char); override;
  8.    public
  9.       procedure AdjustRowHeight(ARow: Integer);
  10.       procedure AdjustRowHeights;
  11.       procedure MoveDownRow;
  12.       procedure MoveUpRow;
  13.  
  14.       constructor Create(anowner:TComponent); override;
  15.    end;
  16.  

 

TinyPortal © 2005-2018