(*//
标题:处理数据网格的编辑框
说明:示例添加焦点颜色;获取还没有提交到数据集的字段文本
设计:Zswang
日期:2002-03-31
支持:wjhu111@21cn.com
//*)
///////Begin Source
function GetDBGridEdit(mDBGrid: TDBGrid): TEdit;
var
I: Integer;
begin
Result := nil;
if not Assigned(mDBGrid) then Exit;
if not mDBGrid.EditorMode then begin
mDBGrid.EditorMode := True;
mDBGrid.EditorMode := False;
end;
with mDBGrid do for I := 0 to Pred(ComponentCount) do
if Components[I] is TCustomEdit then begin
Result := TEdit(Components[I]);
Break;
end;
end; { GetDBGridEdit }
function GetDBGridEditText(mDBGrid: TDBGrid): string;
var
vEdit: TEdit;
begin
vEdit := GetDBGridEdit(mDBGrid);
if Assigned(vEdit) then
Result := vEdit.Text
else Result := ' ';
end; { GetDBGridEditText }
///////End Source
///////Begin Demo
procedure TForm1.DBGrid1Enter(Sender: TObject);
var
vEdit: TEdit;
begin
vEdit := GetDBGridEdit(TDBGrid(Sender));
if Assigned(vEdit) then vEdit.Color := clYellow;
end;
procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Caption := GetDBGridEditText(TDBGrid(Sender));
end;
///////End Demo
标题:处理数据网格的编辑框
说明:示例添加焦点颜色;获取还没有提交到数据集的字段文本
设计:Zswang
日期:2002-03-31
支持:wjhu111@21cn.com
//*)
///////Begin Source
function GetDBGridEdit(mDBGrid: TDBGrid): TEdit;
var
I: Integer;
begin
Result := nil;
if not Assigned(mDBGrid) then Exit;
if not mDBGrid.EditorMode then begin
mDBGrid.EditorMode := True;
mDBGrid.EditorMode := False;
end;
with mDBGrid do for I := 0 to Pred(ComponentCount) do
if Components[I] is TCustomEdit then begin
Result := TEdit(Components[I]);
Break;
end;
end; { GetDBGridEdit }
function GetDBGridEditText(mDBGrid: TDBGrid): string;
var
vEdit: TEdit;
begin
vEdit := GetDBGridEdit(mDBGrid);
if Assigned(vEdit) then
Result := vEdit.Text
else Result := ' ';
end; { GetDBGridEditText }
///////End Source
///////Begin Demo
procedure TForm1.DBGrid1Enter(Sender: TObject);
var
vEdit: TEdit;
begin
vEdit := GetDBGridEdit(TDBGrid(Sender));
if Assigned(vEdit) then vEdit.Color := clYellow;
end;
procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Caption := GetDBGridEditText(TDBGrid(Sender));
end;
///////End Demo
procedure TForm4.dbgrdShowKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
with qry1 do //动态计算
begin
if (FindField('总价')<>nil) and (FindField('数量')<>nil) and (FindField('单价')<>nil) then
if State in [dsinsert,dsedit] then
begin
UpdateRecord;
FieldByName('总价').AsString:=StrOpt(DasS(qry1,'数量'),'*',DasS(qry1,'单价'));
end;
end;
end;