kevincox29
asked on
TwwDBCombobox in delphi 6
I have a TwwDBCombobox with a list of values. How do I get the selected through a procedure,
say, the TwwDBCombobox name is FINGER_L. When it'z onclick event fires, I call this procedure
procedure TFPquality.FINGER_LClick(S ender: TObject);
var description : String;
begin
description := FPquality.FINGER_L.Field.A sString;
end;
However this does not bring the value. I need to use the value of the description in another procedure. Anybody can help?
say, the TwwDBCombobox name is FINGER_L. When it'z onclick event fires, I call this procedure
procedure TFPquality.FINGER_LClick(S
var description : String;
begin
description := FPquality.FINGER_L.Field.A
end;
However this does not bring the value. I need to use the value of the description in another procedure. Anybody can help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you can read the value from the DataSource/DataSet.
ASKER
hi Jimymx,
stilll. onclick event of my FINGER_L TwwDBCombobox does not work . Here is the whole pascal code,
unit FPquality1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,sndkey32,
Dialogs, Grids, Wwdbigrd, Wwdbgrid, DB, Wwdatsrc, OracleData, Oracle,
OraclewwData, wwDataInspector, ExtCtrls, StdCtrls, wwcheckbox, CheckLst,
fcdbtreeview, Buttons, wwdbdatetimepicker, Mask, wwdbedit, Wwdotdot,
Wwdbcomb, ComCtrls, DBCtrls, wwclearbuttongroup, wwradiogroup,
BiDiDBNavigator;
type
TFPquality = class(TForm)
FPQUALITY_T: TOraclewwDataSet;
LIST_T: TOraclewwDataSet;
FPQUALITY_S: TwwDataSource;
FPQUALITY_TFPQUALITY_RN: TFloatField;
FPQUALITY_TCUSTODY_RN: TFloatField;
FPQUALITY_TQUALITY_TYPE: TStringField;
FPQUALITY_TCODE: TStringField;
FPQUALITY_TDESCRIPTION: TStringField;
Panel2: TPanel;
Panel3: TPanel;
FINGER_L: TwwDBComboBox;
ADMIN_L: TwwDBComboBox;
FingerGrid: TwwDBGrid;
AdminGrid: TwwDBGrid;
Panel1: TPanel;
DBNavigator1: TBiDiDBNavigator;
CODE_T: TOraclewwDataSet;
procedure DBNavigator1BeforeAction(S ender: TObject; Button: TNavigateBtn);
procedure ADMIN_LDropDown(Sender: TObject);
procedure FINGER_LDropDown(Sender: TObject);
procedure fpquality_TAfterInsert(Dat aSet: TDataSet);
procedure FINGER_LClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FPquality: TFPquality;
Captype: String;
Finger_rn: LongInt;
description: String;
{$IFDEF WIN32}
Function FPFAILED_START(db,un,pw,ca p: String; rn: LongInt): LongInt; StdCall;
{$ELSE}
Function FPFAILED_START(db,un,pw,ca p: String; rn: LongInt): LongInt;
{$ENDIF}
implementation
Uses HintForm1;
{$R *.dfm}
{------------------------- ---------- ---------- ---------- -------}
Function FPFAILED_START(db,un,pw,ca p: String; rn: LongInt) : LongInt;
begin
Screen.Cursor := crSQLWait;
Captype:= cap;
Finger_rn:= rn ;
try
HINTFORM_START(db,un,pw);
FPquality := TFPquality.Create(Applicat ion);
with FPquality do begin
AdminGrid.Color := TColor(cini.ReadInteger('S ETS', 'GRIDCOLOR', clWhite));
AdminGrid.TitleColor := TColor(cini.ReadInteger('S ETS', 'CAPTIONCOLOR', 10314565));
AdminGrid.TitleFont.Color := TColor(cini.ReadInteger('S ETS', 'CAPTIONFONTCOLOR', clWhite));
FingerGrid.Color := TColor(cini.ReadInteger('S ETS', 'GRIDCOLOR', clWhite));
FingerGrid.TitleColor := TColor(cini.ReadInteger('S ETS', 'CAPTIONCOLOR', 10314565));
FingerGrid.TitleFont.Color := TColor(cini.ReadInteger('S ETS', 'CAPTIONFONTCOLOR', clWhite));
FINGER_L.Color := FingerGrid.Color ;
ADMIN_L.Color := AdminGrid.Color ;
if Captype = 'A'then begin
Panel3.Visible := True;
Panel3.Align := alClient;
end else begin
Panel2.Visible := True;
Panel2.Align := alClient;
end;
Caption := caption + '['+ cap + ']';
With FPQUALITY_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('rn', otInteger);
DeclareVariable('type', otString);
sql.Add('SELECT FPQUALITY.*, FPQUALITY.ROWID FROM MAISY.FPQUALITY');
sql.Add('WHERE FPQUALITY_RN = :rn ');
sql.Add('AND (QUALITY_TYPE = :type)');
SetVariable('rn', Finger_rn);
SetVariable('type', Captype);
Open;
end;
ShowModal;
end;
finally
Screen.Cursor := crDefault;
With FPquality do begin
if (FPQUALITY_S.State = dsEdit) OR (FPQUALITY_S.State = dsInsert) then
FPQUALITY_T.Post;
Result := FPQUALITY_T.RecordCount;
Free;
end;
HINTFORM.Close;
end;
end;
{------------------------- ---------- ---------- ---------- ---------- --------}
procedure TFPquality.ADMIN_LDropDown (Sender: TObject);
begin
if ADMIN_L.Items.Count = 0 then begin
With LIST_T do begin
close;
sql.Clear;
sql.add('SELECT FPQUALITYADMIN.* FROM MLIST.FPQUALITYADMIN ORDER BY DESCRIPTION');
Open;
while not eof do begin
ADMIN_L.Items.Add(FieldByN ame('DESCR IPTION').A sString);
next;
end;
close;
end;
end;
end;
{------------------------- ---------- ---------- ---------- ---------- --------}
procedure TFPquality.FINGER_LDropDow n(Sender: TObject);
begin
if FINGER_L.Items.Count = 0 then begin
With LIST_T do begin
close;
sql.Clear;
sql.add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ORDER BY DESCRIPTION ');
Open;
while not eof do begin
FINGER_L.Items.Add(FieldBy Name('DESC RIPTION'). AsString);
next;
end;
close;
end;
end;
end;
{------------------------- ---------- ---------- ---------- ---------- --------}
procedure TFPquality.fpquality_TAfte rInsert(Da taSet: TDataSet);
var code :String;
begin
With CODE_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('desclist' , otString);
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = :desclist');
SetVariable('desclist', description);
Open;
code := FieldByName('CODE').AsStri ng;
close;
end;
FPQUALITY_TCUSTODY_RN.AsIn teger := Finger_rn;
FPQUALITY_TQUALITY_TYPE.Va lue := captype;
FPQUALITY_TCODE.Value :=code ;
end;
procedure TFPquality.DBNavigator1Bef oreAction( Sender: TObject; Button: TNavigateBtn);
begin
case Button of
nbInsert : Begin
if captype = 'A' then begin
panel1.Visible := True;
DBNavigator1.Visible := True;
AdminGrid.SetFocus;
Sendkeys('{HOME}',False);
AdminGrid.DataSource.DataS et.Append;
end else begin
FingerGrid.SetFocus;
FingerGrid.DataSource.Data Set.Append ;
end;
Abort;
end;
nbEdit : Begin
if captype = 'A' then
AdminGrid.SetFocus
else
FingerGrid.SetFocus;
end;
nbDelete: Begin
if Askdlg_New('Please Confirm','Delete record?','CONFIRM','Yes',' No') = False then
Abort;
end;
end;
end;
procedure TFPquality.FINGER_LClick(S ender: TObject);
var index : Integer;
begin
description := FPquality.FINGER_L.Text;
end;
end.
I am trying to get the selected value of ADMIN_L through TFPquality.FINGER_LClick and try to use in theprocedure TFPquality.fpquality_TAfte rInsert(Da taSet: TDataSet).
All work fine, but I ma unable to get the description value from the ADMIN_L twwdbcombobox . where is the problem??
stilll. onclick event of my FINGER_L TwwDBCombobox does not work . Here is the whole pascal code,
unit FPquality1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,sndkey32,
Dialogs, Grids, Wwdbigrd, Wwdbgrid, DB, Wwdatsrc, OracleData, Oracle,
OraclewwData, wwDataInspector, ExtCtrls, StdCtrls, wwcheckbox, CheckLst,
fcdbtreeview, Buttons, wwdbdatetimepicker, Mask, wwdbedit, Wwdotdot,
Wwdbcomb, ComCtrls, DBCtrls, wwclearbuttongroup, wwradiogroup,
BiDiDBNavigator;
type
TFPquality = class(TForm)
FPQUALITY_T: TOraclewwDataSet;
LIST_T: TOraclewwDataSet;
FPQUALITY_S: TwwDataSource;
FPQUALITY_TFPQUALITY_RN: TFloatField;
FPQUALITY_TCUSTODY_RN: TFloatField;
FPQUALITY_TQUALITY_TYPE: TStringField;
FPQUALITY_TCODE: TStringField;
FPQUALITY_TDESCRIPTION: TStringField;
Panel2: TPanel;
Panel3: TPanel;
FINGER_L: TwwDBComboBox;
ADMIN_L: TwwDBComboBox;
FingerGrid: TwwDBGrid;
AdminGrid: TwwDBGrid;
Panel1: TPanel;
DBNavigator1: TBiDiDBNavigator;
CODE_T: TOraclewwDataSet;
procedure DBNavigator1BeforeAction(S
procedure ADMIN_LDropDown(Sender: TObject);
procedure FINGER_LDropDown(Sender: TObject);
procedure fpquality_TAfterInsert(Dat
procedure FINGER_LClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FPquality: TFPquality;
Captype: String;
Finger_rn: LongInt;
description: String;
{$IFDEF WIN32}
Function FPFAILED_START(db,un,pw,ca
{$ELSE}
Function FPFAILED_START(db,un,pw,ca
{$ENDIF}
implementation
Uses HintForm1;
{$R *.dfm}
{-------------------------
Function FPFAILED_START(db,un,pw,ca
begin
Screen.Cursor := crSQLWait;
Captype:= cap;
Finger_rn:= rn ;
try
HINTFORM_START(db,un,pw);
FPquality := TFPquality.Create(Applicat
with FPquality do begin
AdminGrid.Color := TColor(cini.ReadInteger('S
AdminGrid.TitleColor := TColor(cini.ReadInteger('S
AdminGrid.TitleFont.Color := TColor(cini.ReadInteger('S
FingerGrid.Color := TColor(cini.ReadInteger('S
FingerGrid.TitleColor := TColor(cini.ReadInteger('S
FingerGrid.TitleFont.Color
FINGER_L.Color := FingerGrid.Color ;
ADMIN_L.Color := AdminGrid.Color ;
if Captype = 'A'then begin
Panel3.Visible := True;
Panel3.Align := alClient;
end else begin
Panel2.Visible := True;
Panel2.Align := alClient;
end;
Caption := caption + '['+ cap + ']';
With FPQUALITY_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('rn', otInteger);
DeclareVariable('type', otString);
sql.Add('SELECT FPQUALITY.*, FPQUALITY.ROWID FROM MAISY.FPQUALITY');
sql.Add('WHERE FPQUALITY_RN = :rn ');
sql.Add('AND (QUALITY_TYPE = :type)');
SetVariable('rn', Finger_rn);
SetVariable('type', Captype);
Open;
end;
ShowModal;
end;
finally
Screen.Cursor := crDefault;
With FPquality do begin
if (FPQUALITY_S.State = dsEdit) OR (FPQUALITY_S.State = dsInsert) then
FPQUALITY_T.Post;
Result := FPQUALITY_T.RecordCount;
Free;
end;
HINTFORM.Close;
end;
end;
{-------------------------
procedure TFPquality.ADMIN_LDropDown
begin
if ADMIN_L.Items.Count = 0 then begin
With LIST_T do begin
close;
sql.Clear;
sql.add('SELECT FPQUALITYADMIN.* FROM MLIST.FPQUALITYADMIN ORDER BY DESCRIPTION');
Open;
while not eof do begin
ADMIN_L.Items.Add(FieldByN
next;
end;
close;
end;
end;
end;
{-------------------------
procedure TFPquality.FINGER_LDropDow
begin
if FINGER_L.Items.Count = 0 then begin
With LIST_T do begin
close;
sql.Clear;
sql.add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ORDER BY DESCRIPTION ');
Open;
while not eof do begin
FINGER_L.Items.Add(FieldBy
next;
end;
close;
end;
end;
end;
{-------------------------
procedure TFPquality.fpquality_TAfte
var code :String;
begin
With CODE_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('desclist'
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = :desclist');
SetVariable('desclist', description);
Open;
code := FieldByName('CODE').AsStri
close;
end;
FPQUALITY_TCUSTODY_RN.AsIn
FPQUALITY_TQUALITY_TYPE.Va
FPQUALITY_TCODE.Value :=code ;
end;
procedure TFPquality.DBNavigator1Bef
begin
case Button of
nbInsert : Begin
if captype = 'A' then begin
panel1.Visible := True;
DBNavigator1.Visible := True;
AdminGrid.SetFocus;
Sendkeys('{HOME}',False);
AdminGrid.DataSource.DataS
end else begin
FingerGrid.SetFocus;
FingerGrid.DataSource.Data
end;
Abort;
end;
nbEdit : Begin
if captype = 'A' then
AdminGrid.SetFocus
else
FingerGrid.SetFocus;
end;
nbDelete: Begin
if Askdlg_New('Please Confirm','Delete record?','CONFIRM','Yes','
Abort;
end;
end;
end;
procedure TFPquality.FINGER_LClick(S
var index : Integer;
begin
description := FPquality.FINGER_L.Text;
end;
end.
I am trying to get the selected value of ADMIN_L through TFPquality.FINGER_LClick and try to use in theprocedure TFPquality.fpquality_TAfte
All work fine, but I ma unable to get the description value from the ADMIN_L twwdbcombobox . where is the problem??
Use it OnChange not onClick.
So it becomes:
procedure TFPquality.FINGER_LChange(Sender: TObject);
var
index : Integer;// why it's declared
begin
description := FPquality.FINGER_L.Text;
end;
ASKER
Onchange also does not work.. onExit works but, it takes the previous value selection. may i need to change any property of the ADMIN_L
ASKER
procedure TFPquality.FINGER_LClick(S ender: TObject);
begin
description := FPquality.FINGER_L.Text;
end;
This is the procedure. I remove the
var
index : Integer; where is the problem??
begin
description := FPquality.FINGER_L.Text;
end;
This is the procedure. I remove the
var
index : Integer; where is the problem??
Sorry, I was thinking you are targeting the FINGER_L items. If you want the item from ADMIN_L then:
procedure TFPquality.FINGER_LChange(Sender: TObject);
var
index : Integer;// why it's declared
begin
description := FPquality.ADMIN_L.Text;
end;
You can use it directly in that procedure ".fpquality_TAfterInsert" as follows:
procedure TFPquality.fpquality_TAfterInsert(DataSet: TDataSet);
var code :String;
begin
With CODE_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('desclist', otString);
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = :desclist');
SetVariable('desclist', FPquality.ADMIN_L.Text);
Open;
code := FieldByName('CODE').AsString;
close;
end;
FPQUALITY_TCUSTODY_RN.AsInteger := Finger_rn;
FPQUALITY_TQUALITY_TYPE.Value := captype;
FPQUALITY_TCODE.Value :=code ;
end;
ASKER
sorry, I do want the FINGER_L selected items only, not ADMIN_L. I have written this procedure for the onchange event of the FINGER_L
procedure TFPquality.FINGER_LClick(S ender: TObject);
begin
description := FPquality.FINGER_L.Text;
end;
Again I use the description string value in the procedure
TFPquality.fpquality_TAfte rInsert(Da taSet: TDataSet);
var code :String;
begin
With CODE_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('desclist' , otString);
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = :desclist');
SetVariable('desclist', description);
Open;
code := FieldByName('CODE').AsStri ng;
close;
end;
FPQUALITY_TCUSTODY_RN.AsIn teger := Finger_rn;
FPQUALITY_TQUALITY_TYPE.Va lue := captype;
FPQUALITY_TCODE.Value :=code ;
end;,
I am unable to get the description value, where is the problem?
procedure TFPquality.FINGER_LClick(S
begin
description := FPquality.FINGER_L.Text;
end;
Again I use the description string value in the procedure
TFPquality.fpquality_TAfte
var code :String;
begin
With CODE_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('desclist'
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = :desclist');
SetVariable('desclist', description);
Open;
code := FieldByName('CODE').AsStri
close;
end;
FPQUALITY_TCUSTODY_RN.AsIn
FPQUALITY_TQUALITY_TYPE.Va
FPQUALITY_TCODE.Value :=code ;
end;,
I am unable to get the description value, where is the problem?
What is the DataType of the field DESCRIPTION in the table MLIST.FPQUALITYLAB? if it is a String then you need to add quotes to your parameter, so the SQL in the procedure fpquality_TAfterInsert becomes:
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = ('':desclist'')');
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = ('':desclist'')');
ASKER
still no working. Can U give a sample code to get the selected value of a Twwdbcombobox?
which event is getting getting every selection as best?
which event is getting getting every selection as best?
ASKER
DESCRIPTION VARCHAR2(60)
Then you should set the datatype of the parameter to String or you can add quotes to "description" and use it in the SQL as follows:
TFPquality.fpquality_TAfterInsert(DataSet: TDataSet);
var code :String;
begin
With CODE_T do begin
close;
sql.Clear;
DeleteVariables;
DeclareVariable('desclist', otString);
sql.Add('SELECT FPQUALITYLAB.* FROM MLIST.FPQUALITYLAB ');
sql.Add('WHERE DESCRIPTION = '+ QuotedStr(description));
//SetVariable('desclist', description);
Open;
code := FieldByName('CODE').AsString;
close;
end;
FPQUALITY_TCUSTODY_RN.AsInteger := Finger_rn;
FPQUALITY_TQUALITY_TYPE.Value := captype;
FPQUALITY_TCODE.Value :=code ;
end;
Also have you considered using DBLookupComboBox?
Most likely your value is not yet saved in the Field at OnClick or OnChange event. Have you tried OnCloseUp, that should pick up the selected item
procedure TFPquality.FINGER_LOnClose
begin
description := (Sender as TwwDBComboBox).Text;
end;