一定要设置网格父级MyGrid.Parent := Self;,才会 显示出来
procedure TForm1.FormShow(Sender: TObject); var MyGrid : TStringGrid ; i,j:integer; begin allStringGridList:= TObjectList.Create; //在 uses Contnrs单元 for i := 0 to unit8.Form8.ListBox1.Items.Count-1 do begin MyGrid := TStringGrid.Create(Self); MyGrid.Parent := Self; MyGrid.Visible := true; MyGrid.left := 20+ i*320; MyGrid.top := 20+100*i; MyGrid.rowcount := 5; MyGrid.colcount := 3; MyGrid.width := 210; MyGrid.height := 200; MyGrid.FixedCols:=0; MyGrid.Enabled := true; MyGrid.DragMode:=dmManual; //----------------------------------------------------------------- unit8.Form8.FDMetaInfoQuery1.MetaInfoKind := mkTableFields; unit8.Form8.FDMetaInfoQuery1.ObjectName := unit8.Form8.ListBox1.Items[i]; unit8.Form8.FDMetaInfoQuery1.Active := false; unit8.Form8.FDMetaInfoQuery1.Active := true; MyGrid.RowCount := unit8.Form8.FDMetaInfoQuery1.RecordCount + 1; j := 0; unit8.Form8.FDMetaInfoQuery1.First; while not unit8.Form8.FDMetaInfoQuery1.Eof do begin MyGrid.Cells[0, j + 1] := inttostr(j); MyGrid.Cells[1, j + 1] := unit8.Form8.FDMetaInfoQuery1.FieldByName('COLUMN_NAME').AsString; // '名'; MyGrid.Cells[2, j + 1] := unit8.Form8.FDMetaInfoQuery1.FieldByName('COLUMN_TYPENAME').AsString; // '值'; unit8.Form8.FDMetaInfoQuery1.Next; j := j + 1; end; //============= 弹出 ListBox2m 并获得 焦点=========== ================= MyGrid.Cells[0, 0] := unit8.Form8.ListBox1.Items[i]; MyGrid.Cells[1, 0] := '列名'; MyGrid.Cells[2, 0] := '类型'; MyGrid.ColWidths[0]:=50; MyGrid.ColWidths[1]:=60; MyGrid.ColWidths[2]:=80; MyGrid.OnStartDrag:= StartDrag; MyGrid.OnMouseDown:= MouseDown; MyGrid.OnDragOver := DragOver; MyGrid.OnDragDrop := DragDrop; allStringGridList.Add(MyGrid) ; end; end;
procedure TForm1.MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin end; procedure TForm1.StartDrag(Sender: TObject; var DragObject: TDragObject); begin end; procedure TForm1.DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin end; procedure TForm1.DragDrop(Sender, Source: TObject; X, Y: Integer); begin end;