Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

switch between tables

How can I switch between tables by means of radiobuttons?
(Using ADO)
0
Bosanac
Asked:
Bosanac
  • 8
  • 5
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

in onclick event for the radiobutton assgin the caption to the tablename for adotable

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
  if RadioButton1.Checked then
    ADOTable1.TableName := RadioButton1.Caption ;
    ADOTable1.Open;
end;

Best regards
Mohammed Nasman
0
 
Mohammed NasmanSoftware DeveloperCommented:
sorry forget to add this line   ADOTable1.Close;
so the code will be like the following

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
 if RadioButton1.Checked then
 begin
   ADOTable1.Close;
   ADOTable1.TableName := RadioButton1.Caption ;
   ADOTable1.Open;
end;
end;

but if I prefer to use RadioGroup instead of radiobutton for each table, you will right the code one time, and will work for the all items in the radiogroup, but in radiobutton you need to right the code for each radiobutton

for the RadioGroup the code will be as following

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  if RadioGroup1.ItemIndex =0 then
  begin
    AdoTable1.Close;
    AdoTable1.TableName := RadioGroup1.Items[RadioGroup1.ItemIndex];
    AdoTable1.Open;
  end;
end;

Mohammed
0
 
Mohammed NasmanSoftware DeveloperCommented:
sorry again

 change this line
if RadioGroup1.ItemIndex =0 then

to

if RadioGroup1.ItemIndex >=0 then
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
BosanacAuthor Commented:
And how do I tell my edit which table to search?
Also I want first option to be checked by default and shown when form opens....So 1st table is shown when form opens and so on....
CurrentTable:ADOTable ....something like this..???
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello Bosanac

  if you want the first option to be the default in oncreate event will look like

procedure TForm1.FormCreate(Sender: TObject);
begin
  RadioGroup1.ItemIndex := 0;
  AdoTable1.Close;
  AdoTable1.TableName := RadioGroup1.Items[RadioGroup1.ItemIndex];
  AdoTable1.Open;
end;

and if you want to know the current table, simply u can know that by TableName property

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(AdoTable1.TableName);
end;

I hope that what you need :)

Mohammed
0
 
BosanacAuthor Commented:
It is easier to pass different datasource to grid by means of radiobuttons than manipulating tables.Also I do not like opening tables by their names as I call my tables all sorts,ha,ha....
Any other way???
0
 
BosanacAuthor Commented:
Should it not go like this:

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex =0 then
 begin
   ADOTable2.Close;
   AdoTable1.Close;
   AdoTable1.Open;
   RXDBGrid1.Datasource:=Datasource1;
   DBNavigator1.Datasource:=Datasource1;
   end else begin
   ADOTable1.Close;
   AdoTable2.Close;
   AdoTable2.Open;
   RXDBGrid1.Datasource:=Datasource2;
   DBNavigator1.Datasource:=Datasource2;
end;
end;

??????

0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello again

  I think that what you need?

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  Case RadioGroup1.ItemIndex of
  0 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable1.Open;
      DataSource1.DataSet :=ADOTable1;
    end;
  1 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable2.Open;
      DataSource1.DataSet :=ADOTable2;
    end;
  2:
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable3.Open;
      DataSource1.DataSet :=ADOTable3;
    end;
  end; // case statment
  // no need to duplicate the code for each section, just here only
  RXDBGrid1.DataSource := DataSource1;
  DBNavigator1.DataSource := DataSource1;
end;

// if you click here you will know which talbe assign to the datasource1
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(DataSource1.DataSet.GetNamePath);
end;

Best regards
Mohammed
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello again

  I think that what you need?

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  Case RadioGroup1.ItemIndex of
  0 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable1.Open;
      DataSource1.DataSet :=ADOTable1;
    end;
  1 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable2.Open;
      DataSource1.DataSet :=ADOTable2;
    end;
  2:
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable3.Open;
      DataSource1.DataSet :=ADOTable3;
    end;
  end; // case statment
  // no need to duplicate the code for each section, just here only
  RXDBGrid1.DataSource := DataSource1;
  DBNavigator1.DataSource := DataSource1;
end;

// if you click here you will know which talbe assign to the datasource1
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(DataSource1.DataSet.GetNamePath);
end;

Best regards
Mohammed
0
 
BosanacAuthor Commented:
By the way Mohammed...I fully support you and your people in Palestine.
0
 
Mohammed NasmanSoftware DeveloperCommented:
Thanks alot
are you from Bosna?
0
 
BosanacAuthor Commented:
Yep!
0
 
Mohammed NasmanSoftware DeveloperCommented:
I'm care and support your people too
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now