Recent

Author Topic: what a mistake "tedit can not have tdbgrid as child"  (Read 9891 times)

net_goose

  • New Member
  • *
  • Posts: 23
what a mistake "tedit can not have tdbgrid as child"
« on: March 30, 2010, 10:33:30 am »
Prompt please, how do I bind to TDBgrid TEdit, using it as a drop-down list with data from database

type
TOraDBGrid = class(TrxDBGrid)
protected
procedure CreateParams(var Params:TCreateParams);override;
procedure KeyDown(var Key: word; Shift: TshiftState);override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);override;
procedure Open;
public
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
end;

TOraEdit = class(TEdit)
private
FGrid:TOraDBGrid;
FSession:TOraSession; //TOraSession - компонент ODAC
FSql:String;
...........................


procedure TOraEdit.ShowGrid;
var col:TColumn;
pnt,pnttemp:TPoint;
FullHeigth,FullWidth,ColWidth,H:Integer;
pL,pT:integer;
i:integer;
begin
if Assigned(FGrid) then FGrid.Free;
if not ReadOnly and Enabled then begin
FGrid:=TOraDBGrid.Create(Self);
FGrid.Parent:=Self; //------------------------The error occurs "tedit can not have tdbgrid as child"
FGrid.Font.Assign(Self.Font);
FGrid.Height:=(FGrid.Canvas.TextHeight('*')+3)*10+2;
FGrid.Width:=Width;

with FGrid.Columns do begin
Clear;
FullWidth:=0;
for i:=0 to FShowinfield.Count-1 do begin
col:=Add;
col.FieldName:=FShowinfield;
col.Alignment:=taLeftJustify;
col.Width:=abs(strtoint(FColumnsizelist.Strings));
ColWidth:=col.Width;
FullWidth:=FullWidth+ColWidth;
end;
end;

if FullWidth=0 then begin
FreeAndNil(fGrid); exit;
end else FGrid.Width:=FullWidth+GetSystemMetrics(SM_CXVSCROLL)+2;

pnt:=ClientToScreen(point(0,height));
pL:=pnt.X;
pT:=pnt.Y;
FullWidth:=GetSystemMetrics(SM_CXSCREEN);
FullHeigth:=GetSystemMetrics(SM_CYSCREEN);
if (pT+fgrid.Height)>fullheigth then pT:=pT-fgrid.Height-height-2;
if (pL+fgrid.Width) >fullwidth then pL:=pL-fgrid.width +width;

SetWindowPos(FGrid.Handle, HWND_TOP, pL, pT, 0, 0,SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
FGrid.Visible:=true;
AutoSelect:=false;
SetFocus;
end;
« Last Edit: March 30, 2010, 02:35:39 pm by net_goose »

dfeher

  • New Member
  • *
  • Posts: 19
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #1 on: March 30, 2010, 03:55:44 pm »
I think you may want to reinvent something. You should use TDBComboBox from 'Data Controls' instead.

net_goose

  • New Member
  • *
  • Posts: 23
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #2 on: April 02, 2010, 08:02:56 pm »
Maybe someone knows how to communicate with the developers to clarify this issue? >:(

dfeher

  • New Member
  • *
  • Posts: 19
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #3 on: April 02, 2010, 08:25:54 pm »
maybe

Code: [Select]
FGrid.Parent:=FGrid;
helps...

net_goose

  • New Member
  • *
  • Posts: 23
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #4 on: April 03, 2010, 10:50:56 am »
No component may not be an ancestor of itself!  ;D

eny

  • Hero Member
  • *****
  • Posts: 1631
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #5 on: April 03, 2010, 12:51:56 pm »
FGrid.Parent:=Self; //------------------------The error occurs "tedit can not have tdbgrid as child"

Why would you want to place a TrxDBGrid component, which I assume is something visible, in a TEdit box?
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

net_goose

  • New Member
  • *
  • Posts: 23
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #6 on: April 04, 2010, 07:54:13 am »
This "new" component where Tedit - is, well for example, the text in this field is used to search data in DBGRID!

I am writing TEdit component with drop-down list the type DBGrid.
How would you explain the object DBGRID, serves as a list, and takes data from the database (when creating the object goes to the database and is displaying the necessary data to me), well, for example, a list of city streets.
In Delphi this window through the "setwindowpos" is being drawn under the object TEdit (
as a list similar to the drop-down list TDBComboBox, which is also where he is at the bottom of the form, he falls for the form fields).
I want to be displayed under DBGRID TEdit, the coordinates of which I
compute using ClientTotScreen.
But the problem is that if I write FGrid.parent: = self.Parent (as a form or container), then Lazarus makes Scrolling form (this was also observed in kylix3), suggesting that DBGRID is a component of the form, and it is therefore not should be, and should simply be a window with the data.
Moreover, if the coordinates are outside DBGRID form a window in Delphi is drawn in which the DBGRID me with the necessary data, which covers the form that is drawn on top of it, and even beyond, this is the reason for my part! Simple lists are composed not only of one field, and two, three, four.
I will try to show something like a screen shot.

Sorry for bad English :-[
« Last Edit: April 07, 2010, 07:04:36 am by net_goose »

net_goose

  • New Member
  • *
  • Posts: 23
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #7 on: April 29, 2010, 08:38:38 am »
Prompt please get in touch with developers Lazarus. :'(

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2575
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #8 on: April 29, 2010, 08:52:09 am »
Why don't you use a (customdrawn) combobox ?
What you need for the "popup" is a separate popup kind form/window.
Problem with a separate form/window is that the mainform looses focus. On windows I never got a real solution for this.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Zoran

  • Hero Member
  • *****
  • Posts: 1790
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #9 on: April 29, 2010, 11:37:35 am »
I will try to give you some tips, but I agree with Marc. I think that using custom drown combo box is more elegant solution.

This code creates separate form, puts the grid on it and shows it. When this GridForm is created, you should calculate the correct position on the screen where to show it.

Something like this, in your TOraEditShowGrid procedure:
Code: [Select]

...

if not Assigned(GridForm) then begin // just to be sure

  GridForm := TForm.Create(nil);

  GridForm.ShowInTaskBar := stNever;
  GridForm.BorderStyle := bsNone;
  GridForm.ClientHeight := FGrid.Height;
  GridForm.ClientWidth := FGrid.Width;

  FGrid.Parent := GridForm;
  FGrid.Align := alClient;

  GridClosing := False;
  GridForm.OnClose := @GridFormClose;
  GridForm.OnDeactivate := @GridFormDeactivate;

  H := GridForm.Height;
  W := GridForm.Width;

  P := ControlToScreen(Point(0, Self.Height)); // self is your TOraEdit

  R := Screen.MonitorFromWindow(Self.Handle).WorkareaRect;

  if P.y > R.Bottom - H then
    P.y := P.y - H - Self.Height;

  if P.y < R.Top then
    P.y := R.Top;

  if P.x > R.Right - W then
    P.x := R.Right - W;

  if P.x < R.Left then
    P.x := R.Left;

  GridForm.SetBounds(P.x, P.y, W, H);
  GridForm.Show;
end;


Of course, you must also define GridFormClose and GridFormDeactivate methods.
in GridFormClose, put:
Code: [Select]
GridClosing := True;
CloseAction := caFree;
OraEdit.SetFocus; //do not forget to return focus to your edit control.
GridForm := nil;

in GridFormDeactivate, put:
Code: [Select]
if not GridClosing then GridForm.Close;

And define variable GridClosing: Boolean;
I hope I didn't foget something important...

Paul Ishenin

  • Sr. Member
  • ****
  • Posts: 274
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #10 on: April 29, 2010, 02:13:24 pm »
To solve the paticular exception you can override the next function "function ChildClassAllowed(ChildClass: TClass): boolean; virtual;" in your TOraEdit control. Search lazarus sources for examples.

net_goose

  • New Member
  • *
  • Posts: 23
Re: what a mistake "tedit can not have tdbgrid as child"
« Reply #11 on: April 29, 2010, 05:24:26 pm »
Paul Ishenin, Zoran and others many thanks for the advice, I will try  ;)

 

TinyPortal © 2005-2018