Question

How To Retrieve A Record From A Sorted MS Access ADOTable

Asked by: jsmitter

I need a simple procedure that will take a recently sorted single field MS Access file (ADOTable1.Sort := 'FieldName ASC';) and copy its contents into an array. (The Delphi help menu is proving to be of little value).

I also need to know how to declare it so that it can be accessed from any proceedure in the program.

Thank you for the help.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-05 at 14:18:36ID24710257
Tags

Delphi 7

,

MS Access

Topics

Delphi Database

,

Delphi Programming

Participating Experts
2
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. sort adotables
    hi, i have many tables and when i open them in msaccess they are sorted ascending though opening them in delphi they arent.(note theres no index as such ) i just wish to sort the table ascending via the field named combobox1.text +' Title'. (the active table in delphi is set ...
  2. Empty Access Database in Delphi ADOTABLE!
    If use dbase, just use table1.emptytable can empty the table. How about Access adotable? How to delete all data in Delphi command? Hope get the methods! thx~
  3. ADOTable + DBGrid in delphi
    Hello! I have a ADOTable and one DBGrid I want to list in DBgrid only the record that match with one criteria example only names='john' or only ages > 20 thanks
  4. RETRIEVE FIELDNAMES OF AN SQL TABLE (FIELDNAMES…
    In VB I need to retrieve the fieldnames from an SQL table...NOT the data, just the fieldnames
  5. SQL Server, ADOTable GetInNdexNames, Invalid variant …
    Hello All, I've got an ADOTable in my Delphi 5 application. It connects to an SQL Server Table on our remote web server. The connection works fine. I'm attempting to use the GetIndexNames method to get the available index names and place them in a TListBox. I'm using thi...
  6. Error:  ADOTable -->  "Invalid Object Name"
    Hey there ! I want to use access to an MS-SQL-Server via ADOConnection -> ADOTable. - The connection string in ADOConnection works: "Connected = true" - The connection to ADOTable seems to work, too: In "Table name" I can see all the names and sele...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Geert_GruwezPosted on 2009-09-05 at 21:31:49ID: 25268739

why do you need it in an array ?
a ADOTable is a descendant of a TDataset

you can pass the TAdoTable to a procedure with a TDataset

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

why copy something to memory which is allready in memory ?

procedure ShowDatasetFields(Dataset: TDataset);
var I: Integer;
begin
  for I := 0 to Dataset.Fields.Count - 1 do
    ShowMessage(Format('Field: %s; Value: "%s"', [
      Dataset.Fields.Fields[I].FieldName,
      Dataset.Fields.Fields[I].AsString]));
end;
                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: peterkiersPosted on 2009-09-06 at 03:54:08ID: 25269408

There is an Example from Ciuly on EE.

Search for the question:

Loading,populating and Saving Treeview from database table, urgent please.

And at the bottom you see a link,called:

http://www.ciuly.com/delphi/LoadSaveTreeViewADO.zip

Greetings, Peter Kiers

I hope this will help you.

 

by: Geert_GruwezPosted on 2009-09-06 at 08:29:50ID: 25270309

Rereading the question ...
Do you want all values of a single column sorted ?

you can still pass the TDataset to a procedure like in my first comment
then to go to next record, just use Dataset.Next

 

by: jsmitterPosted on 2009-09-06 at 13:14:58ID: 25271316

Thanks Geert,

The routine is close. This procedure only returns the first record string because it is only a one field list and I need to gain access to every record in the sort list.

I need to be able to pull the string data sequentially from each record location and when getting to the end of the list, start it over again.

Could you give me an example using "DataSet.Next"? As usuall, the help menu didn't bring it to light for me. Thanks

 

by: Geert_GruwezPosted on 2009-09-06 at 22:54:50ID: 25272932

Looks like you're at first steps in Delphi ...
Very good, good choice.
Here are some books to read: http://delphi.veerle-en-geert.be/ebooks.htm

i won't use a array
since you are using a string as a data type --> i'll use a TStringList

if you want to see the strings in a combobox or in a memo:
assuming you have a Button1 on your form and doubleclicked it, you'll get a procedure (event handler) to fill in

procedure TForm1.Button1Click(Sender: TObject);
begin
  // for a combobox
  ColumnDatasetToStrings('FieldName', AdoTable1, ComboBox1.Items);
  // for a memo
  ColumnDatasetToStrings('FieldName', AdoTable1, Memo1.Lines);
end;

procedure ColumnDatasetToStrings(Column: string; Dataset: TDataset; List: TStrings);
begin
  List.BeginUpdate;
  try
    List.Clear;
    Dataset.First;
    while not Dataset.Eof do 
    begin
      List.Add(Dataset.FieldByName(Column).AsString));
      Dataset.Next;
    end;
  finally
    List.EndUpdate;
  end;
end;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: jsmitterPosted on 2009-09-07 at 08:59:53ID: 25275892

Good mornig Geert,

Thanks for the reply. Yep, I'm new at this. This is my third Delphi Project. EE has proved to be an invaluable resource. I'll probably be a life-long member!

The code example looks great in that it will do exactly what I need. However, I can't get a successful compile. I get an "END expected but ')' found" error message on line nine of your example..

I noticed that "FieldByName" is not listed in the autocomplete menu for "Dataset".  Am I doing something wrong?

az
procedure TForm1.ColumnDataSetToStrings(Column: string; Dataset: TDataset; List: TStrings);
begin
 
 with Form1.ADOTable1 do begin
  ADOTable1.Sort := 'ModemID ASC';
 end;
 
  List.BeginUpdate;
  try
    List.Clear;
    Dataset.First;
    while not Dataset.Eof do begin
      List.Add(Dataset.FieldByName(Column).AsString));
      Dataset.Next;
    end;
  finally
    List.EndUpdate
   end;
end;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:

Select allOpen in new window

 

by: Geert_GruwezPosted on 2009-09-07 at 12:25:28ID: 25276862

yeah FieldByName goes missing sometimes
i haven't figured out why yet

hmm let me point out some things so you don't go wondering in the wrong direction strait off

--> you want this code inside your form code,
ok but then you should also get rid of the parameters like this

procedure TForm1.ColumnDataSetToStrings(List: TStrings);
begin
  // do not use Form1 inside TForm1
  // use the variable self instead
  with self.ADOTable1 do
  begin
    ADOTable1.Sort := 'ModemID ASC';
  end;
  // we are not gonna discuss putting the beginning at the *begin* of the line
  // just keep in mind that a line can get very long and
  // you may not see the begin if it is past the end of the screen
  // i do this because i have trained myself to check indentation like this
  // i also do it to detect memory leaks too
 
  // use AdoTable1 instead of Dataset
  List.BeginUpdate;
  try
    List.Clear;
    ADOTable1.First;
    while not ADOTable1.Eof do
    begin
      // Remove the extra ) at the end
      List.Add(ADOTable1.FieldByName('MODEMID').AsString);
      ADOTable1.Next;
    end;
  finally
    List.EndUpdate
   end;
end;

 

by: jsmitterPosted on 2009-09-07 at 14:16:34ID: 25277309

Hey Geert,

Thanks for your patience. I develop real-time control systems and have had to stay in a DOS world (using PowerBasic) alot longer than I would have liked to. This was mainly due to  to the limitations of Windows and all of its wonderful interupts that mess up speed and real-time processing. I'm trying to convert over now.

I must be missing something fundamental here. When I create a function like "procedure PollAccount()". I declare it at the top of the form under the "interface/uses" section. This works ok until I try to access an object on the form- like a button label, or a ADOTable, for instance.

The only way I have been able to make it work is to add TForm1 in front of the procedure and declare it under "TForm1 = class(TForm)" and then declare vars above "implementation" that need to be shared outside of my procedures.

I made the declaration changes as you sugested. However "self" dosen't seem to be reconized by the compiler.

Also, the parameter "List" that is passed in the procedure - "ColumnDataSetToStrings(List: TStrings)", I assumed was the name of the Tmemo or the TListBox that I wanted the fields to be displayed in. That approach didn't compile either.

Oh, thanks for the ebook link. I like the chart. I've been looking for something like that for a long time.

Still stuck.

 

by: Geert_GruwezPosted on 2009-09-07 at 22:56:24ID: 25278969

looks like you will have to post more code to be able to help

the procedure in it self can 't be the problem is the how you use them
probably some fundamentals you're not grasping yet

if you post your code, i'll correct and comment on it

 

by: jsmitterPosted on 2009-09-08 at 08:04:50ID: 25282623

Good morning Geert,

I really appreciate your help! I attached the unit that I'm working with and made some comments where you can see the daclarations that I made. It 's interesting to note that the two procedures that you helped me with, (commented as "EE Procedures") required two different delcaration locations in order to compile.

Second, I don't think that I understand the  "ColumnDataSetToStrings" procedure. I couldn't figure out how to pull a record into a string var or display the data in a TMemo (See button two).

Also, please note that I am using two third party Libraries - IOComp Industrial Components and AsyncPro V4.07.

Thanks again for all your help.

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, iComponent, iVCLComponent, iCustomComponent, iPanel, ComCtrls,
  iLabel, StdCtrls, iSwitchLed, ExtCtrls, OoMisc, AdPort, AdWnPort,
  iThreadTimers, DB, ADODB, Grids, DBGrids, iMotor, iPositionComponent,
  iProgressComponent, iLedBar;
 
 
  procedure PollDelay(Delay_us : LongInt);
  //procedure PollAccount();                          //Doesn't Work Here
  procedure BuildPollArray();
  procedure ShowDataSetFields(DataSet: TDataSet);
  //procedure ColumnDataSetToStrings(List:TStrings);  //Doesn't Work Here
type
 
  TModemIDArray = array[0..42] of String;         //For Development And Testing
 
  TForm1 = class(TForm)
    iPanel1: TiPanel;
    iPanel2: TiPanel;
    iLabel1: TiLabel;
    iLabel2: TiLabel;
    iLabel3: TiLabel;
    iLabel5: TiLabel;
    iLabel6: TiLabel;
    iLabel7: TiLabel;
    iLabel4: TiLabel;
    iLabel8: TiLabel;
    SysComList: TListBox;
    iSwitchLed1: TiSwitchLed;
    iSwitchLed2: TiSwitchLed;
    iPanel3: TiPanel;
    Panel1: TPanel;
    PollingPortRx1: TApdComPort;
    PollingPortRx2: TApdComPort;
    PollingPortTx: TApdComPort;
    HEMComPort: TApdComPort;
    ApdWinsockPort1: TApdWinsockPort;
    ApdWinsockPort2: TApdWinsockPort;
    PollingTimer: TiThreadTimers;
    PollingSw: TiSwitchLed;
    iLabel9: TiLabel;
    Label1: TLabel;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    ADOTable1ModemID: TWideStringField;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    ActivityDisplayList: TMemo;
    iPanel4: TiPanel;
    ManControlCon: TMemo;
    InitHEMButton: TButton;
    SetOutPutAButton: TButton;
    CLROutPutAButton: TButton;
    Button13: TButton;
    SendBlockButton: TButton;
    SendOutPutBButton: TButton;
    CLROutPutBButton: TButton;
    Button17: TButton;
    SendAddressButton: TButton;
    ReturnZonesButton: TButton;
    ReturnParamsButton: TButton;
    Button21: TButton;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    iLedBar1: TiLedBar;
    Panel2: TPanel;
    CLR: TButton;
    ListBox1: TListBox;
    procedure FormActivate(Sender: TObject);
    procedure HEMComPortPortOpen(Sender: TObject);
    procedure HEMComPortTriggerAvail(CP: TObject; Count: Word);
    procedure PollingPortRx1TriggerAvail(CP: TObject; Count: Word);
    procedure PollingPortRx1PortOpen(Sender: TObject);
    procedure PollingPortRx2PortOpen(Sender: TObject);
    procedure PollingPortTxPortOpen(Sender: TObject);
    procedure PollingPortRx2TriggerAvail(CP: TObject; Count: Word);
    procedure PollingTimerTimer1(Sender: TObject);
    procedure PollingSwClick(Sender: TObject);
    procedure InitHEMButtonClick(Sender: TObject);
    procedure SendBlockButtonClick(Sender: TObject);
    procedure SendAddressButtonClick(Sender: TObject);
    procedure SetOutPutAButtonClick(Sender: TObject);
    procedure SendOutPutBButtonClick(Sender: TObject);
    procedure ReturnZonesButtonClick(Sender: TObject);
    procedure CLROutPutAButtonClick(Sender: TObject);
    procedure CLROutPutBButtonClick(Sender: TObject);
    procedure ReturnParamsButtonClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CLRClick(Sender: TObject);
 
    procedure PollAccount();                          //Only Works Here
    procedure ColumnDataSetToStrings(List:TStrings);   //Only Works Here
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
  HEMChar: char;                                    //My Global Vars
  N,P, Block, OldBlock, Address: integer;
  ModemIDArray: TModemIDArray;
  PrintDirectFlag, LoggedOnFlag, ALCUpFlag, ALCDownFlag, PollFlag: Boolean;
  ModemID, PolledModemID: String;
  
implementation
 
{$R *.dfm}
 
procedure TForm1.FormActivate(Sender: TObject);
 Var C : string;  N: integer;
begin
 HEMComPort.Open := True;                         //Initialize ComPorts
 PollingPortRx1.Open := True;
 PollingPortTx.Open := True;
 
 HEMComPort.Output := 'B';                        //Initialize HEM
 HEMComPort.Output := 'Z';
 
 BuildPollArray();                               //Build Test Array
 
 SysComList.Items.Add('System Boot... OK');
 
 N := 0; P := 0;                                 //Set Global Var Initial Value
 
 PollingTimer.Enabled1:= True;
 
end;
 
//****************** Generate Polling List Procedure *************************
procedure BuildPollArray();
 
begin
  //********* Temp Array For Development And Testing **\\
  ModemIDArray[0]  := '0100'; ModemIDArray[1]  := '0101';
  ModemIDArray[2]  := '0102'; ModemIDArray[3]  := '0103';
  ModemIDArray[4]  := '0104'; ModemIDArray[5]  := '0105';
  ModemIDArray[6]  := '0200'; ModemIDArray[7]  := '0201';
  ModemIDArray[8]  := '0202'; ModemIDArray[9]  := '0203';
  ModemIDArray[10] := '0300'; ModemIDArray[11] := '0310';
  ModemIDArray[12] := '0311'; ModemIDArray[13] := '0320';
  ModemIDArray[14] := '0350'; ModemIDArray[15] := '0351';
  ModemIDArray[16] := '0400'; ModemIDArray[17] := '0401';
  ModemIDArray[18] := '0402'; ModemIDArray[19] := '0403';
  ModemIDArray[20] := '0500'; ModemIDArray[21] := '0510';
  ModemIDArray[22] := '0520'; ModemIDArray[23] := '0530';
  ModemIDArray[24] := '0540'; ModemIDArray[25] := '0600';
  ModemIDArray[26] := '0601'; ModemIDArray[27] := '0602';
  ModemIDArray[28] := '0603'; ModemIDArray[29] := '0604';
  ModemIDArray[30] := '0700'; ModemIDArray[31] := '0720';
  ModemIDArray[32] := '0740'; ModemIDArray[33] := '0760';
  ModemIDArray[34] := '0780'; ModemIDArray[35] := '0800';
  ModemIDArray[36] := '0801'; ModemIDArray[37] := '0802';
  ModemIDArray[38] := '0803'; ModemIDArray[39] := '0804';
  ModemIDArray[40] := '0805'; ModemIDArray[41] := '0806';
 
end;
 
//********************** Polling Procedure ***********************************
procedure TForm1.PollAccount();
var
OldBlock: integer;
begin
 PollingSw.Active := True;                       //Turn On Poll Switch
 
 OldBlock := Block;                              //Check if New Block Is Req'd
 Block := StrToInt(ModemIDArray[P]) div 100;        //Process Block
 Address := StrToInt(ModemIDArray[P])-(Block*100);  //Process Address
 
 if Block <> OldBlock then begin             //Test If New Block Req'd
 PollingPortTx.Output := Char($C2);          //Set Block Opcode
 PollDelay(300);                             //300us Req'd For Modem Processing
 PollingPortTx.Output := Char(Block);        //Set Block
 PollDelay(300);                             //300us Req'd For Modem Processing
 PollingPortTx.Output := Char($C1);          //Confirm Block Confirm Opcode
 PollDelay(300);                             //300us Req'd For Modem Processing
 PollingPortTx.Output := Char(Block);        //Confirm Block
 PollDelay(300);
 end;
 
 PollingPortTx.Output := Char(Address);      //Poll Address
 PolledModemID := ModemIDArray[P];           //Buffer For Reporting
 
 if P <= 40 then inc(P) else P:=0;           //For Development And Test Array
 
end;
 
//********************** EE Instructional Proceedures ************************
//********************** Launches With Button Two ****************************
procedure TForm1.ColumnDataSetToStrings(List:TStrings);
 
begin
 with self.ADOTable1 do begin
 ADOTable1.Sort := 'ModemID ASC';
 end;
 
  List .BeginUpdate;
  try
    List.Clear;
    ADOTable1.First;
    while not ADOTable1.Eof do begin
     List.Add(ADOTable1.FieldByName(ModemID).AsString);
      ADOTable1.Next;
    end;
  finally
    List.EndUpdate
  end;
end;
//********************** Launch With Button One ******************************
procedure ShowDataSetFields(DataSet: TDataSet);
Var I: Integer;  C, D: string;
begin
  showmessage(IntToStr(Dataset.RecordCount));         //For Testing
  for I := 0 to DataSet.Fields.Count-1   do begin
    showMessage (Format('Fields:%s; Value: "%s"',     //For Testing
    [DataSet.Fields.Fields[I].FieldName,
    DataSet.Fields.Fields[I].AsString]));
  end;
 
end;
//***************************** End Of EE Procedures *************************
//****************************************************************************
 
 
//************************* ComPort Procedures *******************************
procedure TForm1.HEMComPortPortOpen(Sender: TObject);
begin
SysComList.Items.Add('HEM Com Port... Open');
end;
 
procedure TForm1.PollingPortRx1PortOpen(Sender: TObject);
begin
SysComList.Items.Add('HEM Rx1 Port... Open');
end;
 
procedure TForm1.PollingPortRx2PortOpen(Sender: TObject);
begin
SysComList.Items.Add('HEM Rx2 Port... Open');
end;
 
procedure TForm1.PollingPortTxPortOpen(Sender: TObject);
begin
SysComList.Items.Add('HEM Tx Port... Open');
end;
 
procedure TForm1.HEMComPortTriggerAvail(CP: TObject; Count: Word);
var
I: Word; HEMPacket: String;
begin
 for I := 1 to count do begin
  HEMPacket := HEMPacket + HEMComPort.GetChar;
 end;//for
 
 If PrintDirectFlag then begin
  ManControlCon.Lines.Add(HEMPacket + ' Confirmed');
  PrintDirectFlag := False;
  end
 else if not PrintDirectFlag then begin
  SysComList.Items.Add(HEMPacket +' Confimed');
 end;//if
 
end;
 
procedure TForm1.PollingPortRx1TriggerAvail(CP: TObject; Count: Word);
var
I: Word; C: Char; PacketRx1: String;
begin
 N := N+1;
 for I := 1 to count do begin
   PacketRx1 := PacketRx1 + IntToHex(ord(PollingPortRx1.GetChar),2);
 end;//for
 
 ActivityDisplayList.Lines.Add(PolledModemID+' '+PacketRx1);
 //Label1.Caption := IntToStr(N);//showmessage(IntToStr(N+1));
 //PollAccount();
 
end;
 
procedure TForm1.PollingPortRx2TriggerAvail(CP: TObject; Count: Word);
var
I: Word; C: Char;
begin
 
end;
 
 //*************************Button Functions *********************************
procedure TForm1.PollingSwClick(Sender: TObject);
begin
 
 if PollingTimer.Enabled1 <> True then begin
    PollingSw.Caption := 'Polling ON';
    PollingSw.ActiveColor := clLime;
    PollingTimer.Enabled1 := True;
    //iMotor1.FanOn := True;
 end else if PollingTimer.Enabled1 <> False then begin
    PollingSw.Caption := 'Polling OFF';
    PollingSw.Active := True;
    PollingSw.ActiveColor := clRed;
    PollingTimer.Enabled1 := False;
    //iMotor1.FanOn := False
 end;//if
end;
 
procedure TForm1.InitHEMButtonClick(Sender: TObject);
begin
PrintDirectFlag := True;
HEMComPort.Output := 'B';
HEMComPort.Output := 'Z';
ManControlCon.Clear;
end;
 
procedure TForm1.SendBlockButtonClick(Sender: TObject);
begin
PollingPortTx.Output := Char($C2);
 PollDelay(300);
 PollingPortTx.Output := Char($05);
 PollDelay(300);
 PollingPortTx.Output := Char($C1);
 PollDelay(300);
 PollingPortTx.Output := Char($05);
 PollDelay(1000);
 
 ManControlCon.Lines.Add('Block Sent');
end;
 
procedure TForm1.SendAddressButtonClick(Sender: TObject);
var x: integer;
begin
 for x:= 1 to 1 do begin
  PollingPortTx.Output := Char($00);
  PollDelay(1000);
  PollingPortTx.Output := Char($01);
  ManControlCon.Clear;
 end;
end;
 
procedure TForm1.SetOutPutAButtonClick(Sender: TObject);
begin
 PollingPortTx.Output := Char($B0);
 PollDelay(300);
 PollingPortTx.Output := Char($00);
 ManControlCon.Lines.Add('OutPut "A" Set');
end;
 
procedure TForm1.SendOutPutBButtonClick(Sender: TObject);
begin
 PollingPortTx.Output := Char($A4);
 PollDelay(300);
 PollingPortTx.Output := Char($00);
 ManControlCon.Lines.Add('OutPut "B" Set');
end;
 
procedure TForm1.ReturnZonesButtonClick(Sender: TObject);
begin
 PollingPortTx.Output := Char($92);
 PollDelay(300);
 PollingPortTx.Output := Char($00);
 ManControlCon.Clear;
end;
 
procedure TForm1.CLROutPutAButtonClick(Sender: TObject);
begin
 PollingPortTx.Output := Char($A8);
 PollDelay(300);
 PollingPortTx.Output := Char($00);
 ManControlCon.Lines.Add('OutPut "A" CLR');
end;
 
procedure TForm1.CLROutPutBButtonClick(Sender: TObject);
begin
 PollingPortTx.Output := Char($A2);
 PollDelay(300);
 PollingPortTx.Output := Char($00);
 ManControlCon.Lines.Add('OutPut "B" CLR');
end;
 
procedure TForm1.ReturnParamsButtonClick(Sender: TObject);
begin
PollingPortTx.Output := Char($89);
 PollDelay(300);
 PollingPortTx.Output := Char($00);
 ManControlCon.Clear;
end;
 
procedure TForm1.CLRClick(Sender: TObject);
begin
ManControlCon.Clear;
end;
 
//****************** Timer Procedures ****************************************
procedure TForm1.PollingTimerTimer1(Sender: TObject);
var x, y: integer; Test: string;
begin
PollAccount();
end;
 
//******************** MicroSecond Timer *************************************
procedure PollDelay(Delay_us : LongInt);
var
  time: Int64;
  lasttime: Int64;
  perf_freq: Int64;
  diff: LongInt;
begin
  QueryPerformanceFrequency(perf_freq); //showmessage(IntToStr(perf_freq));
  perf_freq := perf_freq div 1000000;   //Yeilds a value of "3"
  QueryPerformanceCounter(time);
  lasttime := time;                     //Yeilds a value of "1,542,210,808,248
  while True do begin
    QueryPerformanceCounter(time);
    diff := time - lasttime;
    diff := diff div perf_freq;
    if (diff >= Delay_us) then break;
  end;
end;
 
//**************** Buttons For EE Procedures *********************************
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowDataSetFields(ADOTable1);
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
ColumnDataSetToStrings(ListBox1.Items) ;         //Doesn't Work
end;
 
end.

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:

Select allOpen in new window

 

by: Geert_GruwezPosted on 2009-09-08 at 08:30:49ID: 25282904

>>IOComp Industrial Components and AsyncPro V4.07.
Don't have these

explain part 1: your comment: //Only Works Here
procedure/function versus method
a method is a procedure of a object

procedure Test; --> this is a procedure
procedure TForm1.Test; --> this is a method

this is your main problem
you are mixing these types of procedures

from a normal procedure you do not have access to any object variables (or self)
from a method you do

so you need to add
ShowDataSetFields and ColumnDataSetToStrings to the type definition of TForm1 also

when you add your own functions/procedures, add them to the private section


type
  TForm1 = class(TForm)
  ...
  private
    procedure ShowDataSetFields(DataSet: TDataSet);
    procedure ColumnDataSetToStrings(List:TStrings);
  public
  
  end;
 
procedure TForm1.ShowDataSetFields(DataSet: TDataSet);
begin
  ... 
end;
 
procedure TForm1.ColumnDataSetToStrings(List:TStrings);
begin
  ...
end;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

Select allOpen in new window

 

by: Geert_GruwezPosted on 2009-09-08 at 08:33:16ID: 25282928

so your main issue here atm
is your understanding of "method versus procedure"

read this : http://delphi.about.com/od/beginners/a/subroutines.htm

 

by: jsmitterPosted on 2009-09-08 at 12:35:41ID: 25285376

Hey Geert,

OK ,I think I got it! I declare all my own procedures and functions that are methods under type  TForm1 = class/TForm)/private and place the preamble "TForm1" to the front of the procedure name under the implementation. If they're not methods, they get declared at the top under "uses".

Please don't forget about the second question pertaining to the ADOTable string retrieval issue.

Thanks so much

 

by: Geert_GruwezPosted on 2009-09-08 at 13:55:11ID: 25286060

actually there is a technique in delphi which can help you with the declaration of methods

just declare it in the type definition
and then hit Shift-Ctrl C (this is called class completion)

second Q
have you got the data in the AdoTable1 activated ?

you can check this by adding a TDatasource and a TDBGrid
set property Datasource1 Dataset to AdoTable
and property DBGrid1 Datasource to Datasource1

you should see all your data in the DBgrid

 

by: jsmitterPosted on 2009-09-08 at 14:18:49ID: 25286270

Hey Geert,

I can see the data in the ADOTable using the method you suggest ( already did that). But, I need to be able to pull each record out from the table, one at a time, and pass it on to a procedure.

 

by: Geert_GruwezPosted on 2009-09-09 at 12:39:14ID: 25294782

do you understand TStrings.Values ?

var List: TStrings;
begin
  List := TStringList.Create;
  try
    List.Values['MODEMID'] := 2;
    List.Values['STATUS'] := 'Online';
  finally
    List.Free;
  end;
end;

and then use that with the AdoTable

procedure TForm1.Button1Click(Sender: TObject);
var List: TStrings;
begin
  List := TStringList.Create;
  try
    AdoTable1.First;
    while not AdoTable1.Eof do
    begin
      List.Values['MODEMID'] := AdoTable1.FieldByName('MODEMID').AsString;
      List.Values['STATUS'] := AdoTable1.FieldByName('STATUS').AsString;
      YourProc(List);
      AdoTable1.Next;
    end;
  finally
    List.Free;
  end;
end;
 
procedure TForm1.YourProc(RecordList: TStrings);
var I: integer;
begin
  for I := 0 to List.Count-1 do
    ShowMessage(Format('Name: %s; Value: %s', [List.Names[I], List.ValueFromIndex[I]));
end;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:

Select allOpen in new window

 

by: jsmitterPosted on 2009-09-10 at 09:05:30ID: 31625350

Thank Geert,

You helped me with alot more a than just one question here. I wish there was a way to give you more points than just 500.

Take care

 

by: Geert_GruwezPosted on 2009-09-10 at 12:27:51ID: 25303402

hey no problem
ask away

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...