关于DBGrid控件的使用问题和控件数组的问题及Select的问题(100分)

  • 主题发起人 delphi_bt
  • 开始时间
D

delphi_bt

Unregistered / Unconfirmed
GUEST, unregistred user!
1。当把DBGrid控件的dgMultiSelect属性设置为False时,如何确定DBGrid控件中被选中的行;
2。当一个Form中放置了若干个同类控件,如label1,label2,label3...,如果想通过循环对其进行处理怎么做,
form1.InsertControl();form1.InsertComponent()这两个方法是什么意思,怎么用,最好举个例子;
3。当ADOQuery返回一个数据集,如何直接将其存入一个数组内(不考虑数据类型不匹配的问题)
谢谢各位大虾。
 
好象无法直接得到DBGrid的被选中的当前行,
可以通过字段值来在对应表中再判断当前记录位置
 
当前被选中的行应该就是Table中的当前记录,可以通过recno确定吧
对label1,label2.....好像不能直接通过循环来控制,可以用控件数组来控制
保存到数组,似乎应该在定义数组时做些手脚,看看下面的帮助吧,也许对你有用
You cannot assign an ordinary static array to a variant. Instead, create a variant array by calling either of the standard functions VarArrayCreate or VarArrayOf. For example,

V: Variant;

...
V := VarArrayCreate([0,9], varInteger);

creates a variant array of integers (of length 10) and assigns it to the variant V. The array can be indexed using V[0], V[1], and so forth, but it is not possible to pass a variant array element as a var parameter. Variant arrays are always indexed with integers.
The second parameter in the call to VarArrayCreate is the type code for the array’s base type. For a list of these codes, see VarType. Never pass the code varString to VarArrayCreate; to create a variant array of strings, use varOleStr.

Variants can hold variant arrays of different sizes, dimensions, and base types. The elements of a variant array can be of any type allowed in variants except ShortString and
AnsiString, and if the base type of the array is Variant, its elements can even be heterogeneous. Use the VarArrayRedim function to resize a variant array. Other standard routines that operate on variant arrays include VarArrayDimCount, VarArrayLowBound, VarArrayHighBound, VarArrayRef, VarArrayLock, and VarArrayUnlock.

When a variant containing a variant array is assigned to another variant or passed as a value parameter, the entire array is copied. Don’t perform such operations unnecessarily, since they are memory-inefficient.
 
第二个问题:
var i:integer;
begin
for i:=0 to ComponentCount-1 do
begin
if Components is TLabel then
(Components as TLabel ) .......
end;
 
谢谢大家的热心帮助!
 
顶部