Can someone help me out with writing a class file. I am constatly re-using the same block of code throughout my program (with different parameters). The only thing that really differs is the SQL query. Here is the code:
procedure TfrmMain.LoadCustomers;
var
i : Integer; //variable to loop through query recordset
ADOLoadQuery : TADOQuery;
begin
//initiate empty query
ADOLoadQuery := TADOQuery.Create(nil);
//set ADOQuery connection string
ADOLoadQuery.ConnectionString := connString;
//set the SQL search string for the ADO Query
ADOLoadQuery.SQL.Text := 'Select distinct CUST_CODE, TEMP_NO ' +
'From invoice_data';
ADOLoadQuery.Open; //Open query and connection
//loop through recordset
with ADOLoadQuery.Recordset do
begin
if (RecordCount > 0) then
begin
MoveFirst; //Move to the first record
//loop through SQL query dataset and retrieve corresponding data
for i := 1 to RecordCount do
begin
//add all the customer codes available to the comboboxes on
//the 'View/Modify' form and the 'Delete' form.
//add both customer code + template no. to the combobox on the
//import form
cboExportCustTemp.Items.Add(Fields['CUST_CODE'].Value +
' TEMP NO: ' + FloatToStr(Fields['TEMP_NO'].Value));
if cboDeleteCustomerCode.Items.IndexOf(Fields['CUST_CODE'].Value) = -1 then
cboDeleteCustomerCode.Items.Add(Fields['CUST_CODE'].Value);
if cboViewCustCode.Items.IndexOf(Fields['CUST_CODE'].Value) = -1 then
cboViewCustCode.Items.Add(Fields['CUST_CODE'].Value);
MoveNext; //Move to the next record
end;
end;
end;
ADOLoadQuery.Close; //close query and connection
//select the first item in the combo boxes
cboDeleteCustomerCode.ItemIndex := 0;
cboViewCustCode.ItemIndex := 0;
cboExportCustTemp.ItemIndex := 0;
end;
Any suggestions or comments are welcome.
Thanks.
------------------------------------
There's no place like 127.0.0.1
------------------------------------
procedure TfrmMain.LoadCustomers;
var
i : Integer; //variable to loop through query recordset
ADOLoadQuery : TADOQuery;
begin
//initiate empty query
ADOLoadQuery := TADOQuery.Create(nil);
//set ADOQuery connection string
ADOLoadQuery.ConnectionString := connString;
//set the SQL search string for the ADO Query
ADOLoadQuery.SQL.Text := 'Select distinct CUST_CODE, TEMP_NO ' +
'From invoice_data';
ADOLoadQuery.Open; //Open query and connection
//loop through recordset
with ADOLoadQuery.Recordset do
begin
if (RecordCount > 0) then
begin
MoveFirst; //Move to the first record
//loop through SQL query dataset and retrieve corresponding data
for i := 1 to RecordCount do
begin
//add all the customer codes available to the comboboxes on
//the 'View/Modify' form and the 'Delete' form.
//add both customer code + template no. to the combobox on the
//import form
cboExportCustTemp.Items.Add(Fields['CUST_CODE'].Value +
' TEMP NO: ' + FloatToStr(Fields['TEMP_NO'].Value));
if cboDeleteCustomerCode.Items.IndexOf(Fields['CUST_CODE'].Value) = -1 then
cboDeleteCustomerCode.Items.Add(Fields['CUST_CODE'].Value);
if cboViewCustCode.Items.IndexOf(Fields['CUST_CODE'].Value) = -1 then
cboViewCustCode.Items.Add(Fields['CUST_CODE'].Value);
MoveNext; //Move to the next record
end;
end;
end;
ADOLoadQuery.Close; //close query and connection
//select the first item in the combo boxes
cboDeleteCustomerCode.ItemIndex := 0;
cboViewCustCode.ItemIndex := 0;
cboExportCustTemp.ItemIndex := 0;
end;
Any suggestions or comments are welcome.
Thanks.
------------------------------------
There's no place like 127.0.0.1
------------------------------------