?
Solved

What's wrong with this?

Posted on 2004-04-16
3
Medium Priority
?
179 Views
Last Modified: 2010-04-05
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(Application.ExeName) + '\snippits.mdb';
 try
  ADOConnection1.ConnectionString :=
            'Provider=Microsoft.Jet.OLEDB.4.0;' +
            'Data Source=' + Data +';'+
            'Persist Security Info=False';
  ADOConnection1.Open;
  ADOConnection1.GetTableNames(AccessTableNames);
  ADOConnection1.Close;
 finally
  for i := 0 to AccessTableNames.Count -1 do
   RadioGroup1.Items.Add(AccessTableNames[i]);
  AccessTableNames.Free;
 end;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
var
  Tbl:TADOTable;
begin
  Tbl:=TADOTable.Create(Self);
    try
      Tbl.Connection:=ADOConnection1;
      Tbl.TableName:=RadioGroup1.Items[RadioGroup1.ItemIndex];
      Tbl.Open;

        with Tbl do
        begin
          First;
          ListBox1.Items.Clear;
            while not eof do
            begin
              ListBox1.Items.Add(FieldByName('Title').text);
              Next;
            end;
        end;
    finally
      Tbl.Active:=False;
      Tbl.Free;
end;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var
  Tbl:TADOTable;
begin
   Memo1.Clear;
   Tbl:=TADOTable.Create(Self);
   try
    Tbl.Connection:=ADOConnection1;
    Tbl.TableName:=RadioGroup1.Items[RadioGroup1.ItemIndex];
    Tbl.Open;
  tbl.Active := false;
     tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items.ValueFromIndex[radiogroup1.itemindex]);
     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').asstring;
    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
0
Comment
Question by:fibdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Author Comment

by:fibdev
ID: 10847134
So, to sum it up

My filter is returning undesirable results...

'Hello World' is showing up as 'ello World'.

This is causing my Memo1 to not be populated.  :(
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 10848181
instead of

     tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items.ValueFromIndex[radiogroup1.itemindex]);
     
use


     tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items[radiogroup1.itemindex]);
     
meikl ;-)
0
 
LVL 3

Author Comment

by:fibdev
ID: 10849402
Well,

I have it working, but I'm sure there's a better way...

procedure TForm1.ListBox1Click(Sender: TObject);
var
  Tbl:TADOTable;
  CodeText : String;
begin
   Memo1.Clear;
   Tbl:=TADOTable.Create(Self);
   try
    Tbl.Connection:=ADOConnection1;
    Tbl.TableName:=RadioGroup1.Items[RadioGroup1.ItemIndex];
    Tbl.Open;
  tbl.Active := false;
     tbl.Filter := 'Title = ' + QuotedStr(ListBox1.Items[ListBox1.ItemIndex]);
     tbl.Filtered := True;
 form1.Caption := 'Fibdev SnipSnap 1.0 - Code Library' + ' (' + tbl.tablename + ')';
  tbl.Active := True;
    with tbl do
    begin
      CodeText := FieldbyName('Code').AsString;
    end;
      Memo1.lines.Add(CodeText);
       finally
      Tbl.Active:=False;
      Tbl.Free;
  end;
end;
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question