fibdev
asked on
What's wrong with this?
I have two issues, and I'm not sure if they are related, but here is the code...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Menus, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
RadioGroup1: TRadioGroup;
ListBox1: TListBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
Data : String;
i: Integer;
AccessTableNames: TStringList;
begin
AccessTableNames := TStringList.Create;
Data := ExtractFilePath(Applicatio n.ExeName) + '\snippits.mdb';
try
ADOConnection1.ConnectionS tring :=
'Provider=Microsoft.Jet.OL EDB.4.0;' +
'Data Source=' + Data +';'+
'Persist Security Info=False';
ADOConnection1.Open;
ADOConnection1.GetTableNam es(AccessT ableNames) ;
ADOConnection1.Close;
finally
for i := 0 to AccessTableNames.Count -1 do
RadioGroup1.Items.Add(Acce ssTableNam es[i]);
AccessTableNames.Free;
end;
end;
procedure TForm1.RadioGroup1Click(Se nder: TObject);
var
Tbl:TADOTable;
begin
Tbl:=TADOTable.Create(Self );
try
Tbl.Connection:=ADOConnect ion1;
Tbl.TableName:=RadioGroup1 .Items[Rad ioGroup1.I temIndex];
Tbl.Open;
with Tbl do
begin
First;
ListBox1.Items.Clear;
while not eof do
begin
ListBox1.Items.Add(FieldBy Name('Titl e').text);
Next;
end;
end;
finally
Tbl.Active:=False;
Tbl.Free;
end;
end;
procedure TForm1.ListBox1Click(Sende r: TObject);
var
Tbl:TADOTable;
begin
Memo1.Clear;
Tbl:=TADOTable.Create(Self );
try
Tbl.Connection:=ADOConnect ion1;
Tbl.TableName:=RadioGroup1 .Items[Rad ioGroup1.I temIndex];
Tbl.Open;
tbl.Active := false;
tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items.V alueFromIn dex[radiog roup1.item index]);
tbl.Filtered := True;
tbl.Active := True;
with tbl do
begin
{------------------------- ---------- ---------- ---------
This isn't working because the first char of my 'Title' string is being trimmed off
-------------------------- ---------- ---------- ---------- }
Memo1.Text := Fieldbyname('Code').asstri ng;
end;
finally
{------------------------- ---------- ---------- ---------
One of my table names is 'c++' and so I'm getting an error when I select it in my RadioGroup
-------------------------- ---------- ---------- ---------}
Tbl.Active:=False;
Tbl.Free;
end;
end;
end.
// Thanks in advance!
// Gabe
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Menus, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
RadioGroup1: TRadioGroup;
ListBox1: TListBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
Data : String;
i: Integer;
AccessTableNames: TStringList;
begin
AccessTableNames := TStringList.Create;
Data := ExtractFilePath(Applicatio
try
ADOConnection1.ConnectionS
'Provider=Microsoft.Jet.OL
'Data Source=' + Data +';'+
'Persist Security Info=False';
ADOConnection1.Open;
ADOConnection1.GetTableNam
ADOConnection1.Close;
finally
for i := 0 to AccessTableNames.Count -1 do
RadioGroup1.Items.Add(Acce
AccessTableNames.Free;
end;
end;
procedure TForm1.RadioGroup1Click(Se
var
Tbl:TADOTable;
begin
Tbl:=TADOTable.Create(Self
try
Tbl.Connection:=ADOConnect
Tbl.TableName:=RadioGroup1
Tbl.Open;
with Tbl do
begin
First;
ListBox1.Items.Clear;
while not eof do
begin
ListBox1.Items.Add(FieldBy
Next;
end;
end;
finally
Tbl.Active:=False;
Tbl.Free;
end;
end;
procedure TForm1.ListBox1Click(Sende
var
Tbl:TADOTable;
begin
Memo1.Clear;
Tbl:=TADOTable.Create(Self
try
Tbl.Connection:=ADOConnect
Tbl.TableName:=RadioGroup1
Tbl.Open;
tbl.Active := false;
tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items.V
tbl.Filtered := True;
tbl.Active := True;
with tbl do
begin
{-------------------------
This isn't working because the first char of my 'Title' string is being trimmed off
--------------------------
Memo1.Text := Fieldbyname('Code').asstri
end;
finally
{-------------------------
One of my table names is 'c++' and so I'm getting an error when I select it in my RadioGroup
--------------------------
Tbl.Active:=False;
Tbl.Free;
end;
end;
end.
// Thanks in advance!
// Gabe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well,
I have it working, but I'm sure there's a better way...
procedure TForm1.ListBox1Click(Sende r: TObject);
var
Tbl:TADOTable;
CodeText : String;
begin
Memo1.Clear;
Tbl:=TADOTable.Create(Self );
try
Tbl.Connection:=ADOConnect ion1;
Tbl.TableName:=RadioGroup1 .Items[Rad ioGroup1.I temIndex];
Tbl.Open;
tbl.Active := false;
tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items[L istBox1.It emIndex]);
tbl.Filtered := True;
form1.Caption := 'Fibdev SnipSnap 1.0 - Code Library' + ' (' + tbl.tablename + ')';
tbl.Active := True;
with tbl do
begin
CodeText := FieldbyName('Code').AsStri ng;
end;
Memo1.lines.Add(CodeText);
finally
Tbl.Active:=False;
Tbl.Free;
end;
end;
I have it working, but I'm sure there's a better way...
procedure TForm1.ListBox1Click(Sende
var
Tbl:TADOTable;
CodeText : String;
begin
Memo1.Clear;
Tbl:=TADOTable.Create(Self
try
Tbl.Connection:=ADOConnect
Tbl.TableName:=RadioGroup1
Tbl.Open;
tbl.Active := false;
tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items[L
tbl.Filtered := True;
form1.Caption := 'Fibdev SnipSnap 1.0 - Code Library' + ' (' + tbl.tablename + ')';
tbl.Active := True;
with tbl do
begin
CodeText := FieldbyName('Code').AsStri
end;
Memo1.lines.Add(CodeText);
finally
Tbl.Active:=False;
Tbl.Free;
end;
end;
ASKER
My filter is returning undesirable results...
'Hello World' is showing up as 'ello World'.
This is causing my Memo1 to not be populated. :(