Page 1 of 1

get.cell.font.size (2)

Posted: Sat May 26, 2007 2:06 pm
by j&b
Hello Sergey,

your solution runs fine.
Now I tried it at another position in programm (if someone presses key "1" (number one) program shall write "Paul" in the cell, if someone press the 2, code shall write something oher in the the 3. cell), but I always get an error. The last try shows an eAcessViolation-hint.
It must be be a very,very small mistake. Can you eliminate him ? (I hope so)




procedure TForm1.memoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var r,c,cs,rs,ItemNo,Data,Offs, styleNo,paraNo: Integer;
begin
if (ssCtrl in Shift) then begin

end else begin
if { (not memo.CanChange) or } (not memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable))) then exit;
if (key>48) and (key<57) then begin
if key=49 then s:= fverbBeno[1] else if key=50 then s:= fverbBeno[2] else if key=51 then s:= fverbBeno[3]
else if key=52 then s:= fverbBeno[4] else if key=53 then s:= fverbBeno[5] else if key=54 then s:= fverbBeno[6]
else if key=55 then s:= fverbBeno[7] else if key=56 then s:= fverbBeno[8];

memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable));
ItemNo := memo.GetItemNo(rveTable);
memo.BeginItemModify(ItemNo, Data);
rveTable.GetSelectionBounds(r,c,i,j); // akt. Row + Col

if (rveTable.colCount=3) and (c=2) then begin
if (rveTable.Cells[r,2]<>nil) and (rveTable.Cells[r,2].GetRVData.GetItemStyle(0)>=0) then begin
styleNo := rveTable.Cells[r,2].GetRVData.GetItemStyle(0);
ParaNo := rveTable.Cells[r,2].GetRVData.GetItemPara(0);
rveTable.Cells[r,2].clear;
rveTable.Cells[r,2].AddNL(s,StyleNo,ParaNo);
end;

//if rveTable<>nil then begin
memo.EndItemModify(ItemNo, Data);
memo.Change;
//end;
if table1.state in [dsEdit, dsInsert] then table1.post;
ShowMessage(intToStr(r)+' '+intToStr(c)); //After showing row + col program shows an error-message (EAccessViolation)
end;
end;
end;


procedure TForm1.memoChange(Sender: TObject);
begin
if fModified=false then begin
pPostenSch.enabled:=true; pPostenBem.enabled:=true; pPosten.Visible:=true;
fModified:=true; //zum Steuern von pPosten - pPosten = aktiv
end;
lAktZmemo.Caption:=intToStr(memoZeile);
lAnzZmemo.Caption:=intToStr(HowManyLines(memo));
memo.Reformat; // keeps the selection (and caret position )
if memo.InplaceEditor<>nil then memo.InplaceEditor.Invalidate;
end;

Posted: Fri Jun 01, 2007 1:03 pm
by j&b
Here the (very fine running) solution from Sergey:

In OnKeyDown, you cannot do any actions that destroy cell inplace editor. Not only clearing document or deleting the current table destroy the inplace editor. Any actions that move caret outside of the current cell destroys the cell inplace editor.
Unfortunately, I cannot remove this limitation.

The solution is using PostMessage function.

1. Define an unique constant larger than WM_USER, for example const WM_DOSOMETHINGINTABLE = WM_USER+1;
2. add procedure WMDoSomethingInTable(var Msg: TMessage); message WM_DOSOMETHINGINTABLE;
3. change memo.OnKeyDown:

//-------------------------------------------------



unit Unit1;

interface

uses windows,... ;

const WM_DOSOMETHINGINTABLE = WM_USER+2; //für memotable and OnKeyDown

...

type
TForm1 = class(TForm)
...
procedure WMDoSomethingInTable(var Msg: TMessage); message WM_DOSOMETHINGINTABLE; //für memotable and OnKeyDown
...
Private
...
public
...
end;

var
Form1: TForm1;

implementation

{$R *.dfm}


...

procedure TForm1.memoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (ssCtrl in Shift) then begin
...
end else begin
if (key>48) and (key<57) and (memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable))) then
PostMessage(Handle, WM_DOSOMETHINGINTABLE, Key, 0); //für memotable and OnKeyDown
end;
end;

procedure TForm1.WMDoSomethingInTable(var Msg: TMessage);
var r,c,cs,rs,ItemNo,Data,Offs, styleNo,paraNo: Integer;
Key: Word;
begin //für memotable and OnKeyDown
key := Msg.WParam;
if key=49 then s:= fverbBeno[1] else if key=50 then s:= fverbBeno[2] else if key=51 then s:= fverbBeno[3]
else if key=52 then s:= fverbBeno[4] else if key=53 then s:= fverbBeno[5] else if key=54 then s:= fverbBeno[6]
else if key=55 then s:= fverbBeno[7] else if key=56 then s:= fverbBeno[8];

memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable));
ItemNo := memo.GetItemNo(rveTable);
memo.BeginItemModify(ItemNo, Data);
rveTable.GetSelectionBounds(r,c,i,j);

if (rveTable.colCount=3) and (c=2) then begin // there ist still another table (with 6 cols)
if (rveTable.Cells[r,2]<>nil) and (rveTable.Cells[r,2].GetRVData.GetItemStyle(0)>=0) then begin
styleNo := rveTable.Cells[r,2].GetRVData.GetItemStyle(0);
ParaNo := rveTable.Cells[r,2].GetRVData.GetItemPara(0);
rveTable.Cells[r,2].clear;
rveTable.Cells[r,2].AddNL(s,StyleNo,ParaNo);
end;

memo.EndItemModify(ItemNo, Data);
memo.Change;
if table1.state in [dsEdit, dsInsert] then table1.post;
end;
end;