Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inplace editors

8 views
Skip to first unread message

Boki

unread,
May 15, 2002, 9:20:59 PM5/15/02
to
Hi Everybody,

I'm making TStrigGrid - like (TCustomControl desc.) component and I want to
implement inplace editor - when user click with mouse on one cell.

I want to use TCustomEdit (or one my descendant from TCustomEdit) for this
purpose, but I have problem to show and use this Edit control.

I'm trying with

var
CellEdit: TCustomEdit
begin
CellEdit:=TCustomEdit.Create(Self);

But this not show edit control in grid. I' am adjust Left and Top properties
, but this have no affect.

What is all need to do, to implement InplaceEdit?

Thanks for answers

Boki


Paul Nicholls

unread,
May 15, 2002, 10:38:24 PM5/15/02
to
Have you set these paremeters?
CellEdit.Parent := Self;
CellEdit.Visible := True;

--
Paul Nicholls (Delphi 5 Professional)
"Life is like a road - occasionally you run into potholes or get blowouts." -
Paul Nicholls

HomePage: www.southcom.com.au/~phantom
Email: paul_f_...@antispam.hotmail.com
(Remove "antispam." to reply)
"Boki" <nbo...@hotmail.com> wrote in message news:3ce309a8_2@dnews...

Sean Dockery

unread,
May 16, 2002, 12:52:17 PM5/16/02
to
Hi, Boki.

Here's an article that I wrote some time ago to help someone detect when an
InplaceEdit became visible and was hidden.

<snip>

The in-place edit is shown and hidden using SetWindowPos, so you can do a
little magic with WM_WINDOWPOSCHANGED. Below is a little bit of code that I
whipped up to do it...

Replace 'TCimInplaceEdit' with your own class, but add the appropriate
code...

TCimInplaceEdit = class(TInplaceEdit)
private
FPrevious: Boolean;
FOnHide: TNotifyEvent;
FOnShow: TNotifyEvent;
procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message
WM_WINDOWPOSCHANGED;
published
property OnHide: TNotifyEvent read FOnHide write FOnHide;
property OnShow: TNotifyEvent read FOnShow write FOnShow;
end;

procedure TCimInplaceEdit.WMWindowPosChanged(
var Message: TWMWindowPosChanged);
begin
inherited;

if FPrevious <> Visible then
begin
FPrevious := Visible;

if Visible then
begin
if Assigned(FOnShow) then
FOnShow(Self);
end
else
begin
if Assigned(FOnHide) then
FOnHide(Self);
end;
end;
end;

Replace TCimStringGrid, TCimInplaceEdit with your own classes, but add the
appropriate code... You also probably don't want to inherit off of
TStringGrid. :-)

TCimStringGrid = class(TStringGrid)
private
FInPlaceEdit: TCimInplaceEdit;
FOnCreateEditor: TNotifyEvent;
protected
function CreateEditor: TInplaceEdit; override;
public
property InplaceEdit: TCimInplaceEdit read FInPlaceEdit;
published
property OnCreateEditor: TNotifyEvent read FOnCreateEditor write
FOnCreateEditor;
end;


function TCimStringGrid.CreateEditor: TInplaceEdit;
begin
// Necessary to keep internal reference of FInplaceEdit for OnCreateEditor
// callback. Could've created a custom event type for
TOnCreateEditorEvent
// that included the value instead...

FInplaceEdit := TCimInplaceEdit.Create(Self);
Result := FInplaceEdit;

if not (csDesigning in ComponentState) and Assigned(FOnCreateEditor) then
FOnCreateEditor(Self);
end;

Create an event handler for OnCreateEditor and do this:

procedure TForm1.CimStringGrid1CreateEditor(Sender: TObject);
begin
CimStringGrid1.InplaceEdit.OnHide := InplaceEditHide;
CimStringGrid1.InplaceEdit.OnShow := InplaceEditShow;
end;

procedure TForm1.InplaceEditHide(Sender: TObject);
begin
OutputDebugString('Hide');
end;

procedure TForm1.InplaceEditShow(Sender: TObject);
begin
OutputDebugString('Show');
end;

</snip>

Just remove the superfluous code to get what you want: Creating your own
custom TInplaceEdit for a TStringGrid. Then go from there...

You can find the entire article and thread on the Tamarack Associates web
site:

http://216.101.185.148/scripts/isapi.dll/article?id=0440795A&article=1783233

I also recommend scouring the Google results:

http://groups.google.com/groups?q=InplaceEdit+Delphi+Grid

Good luck.

Sean Dockery
SBD Consultants
se...@sbdconsultants.com

"Boki" <nbo...@hotmail.com> wrote in message news:3ce309a8_2@dnews...

Boki

unread,
May 16, 2002, 1:21:29 PM5/16/02
to
Thanks, this is it!


Boki

unread,
May 16, 2002, 1:25:40 PM5/16/02
to
Thanks Sean, I am not using TInplaceEdit descentant, I am using TCustomEdit
descentant. But I will use very nice WM_WINDOWPOSCHANGED message.


0 new messages