Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Migrating from vb to delphi

Posted on 1999-06-29
13
Medium Priority
?
168 Views
Last Modified: 2010-04-06
I have the fallowing problems:

I Want to make a procedure like this

procedure fill_tab;
begin

  TC_produtos.TabHeight := 30;
  with TB_Produtos do
  begin
    Close;
    IndexName := 'PorNome';
    Open;
    while not EOF do
    begin
      TC_Produtos.Tabs.Add(FieldByName('Desig').AsString);
      SL_Id_Produtos.Add(FieldByName('id_produto').AsString);
      Next;
    end;
    First;
  end;

end;

and then call it from this places:

procedure TF_Produtos.FormCreate(Sender: TObject);
begin
  SL_Id_produtos := tstringlist.create;
  fill_tab;
end;

procedure TF_Produtos.B_P_ApagarClick(Sender: TObject);

var sql:string;

begin

     sql:= 'DELETE FROM produtos WHERE id_produto=';
     sql:= sql + L_P_ID.caption;
     query1.sql.clear;
     query1.SQL.Add(sql);
     query1.ExecSQL;

     fill_tab;

end;

but it gives me several errors saying that tc_produtos wich is a
tabcontrol is not defined, but he is defined.
if i use the following it works but i can´t call it

procedure TF_Produtos.FormCreate(Sender: TObject);
begin
  SL_Id_produtos := tstringlist.create;
  TC_produtos.TabHeight := 30;
  with TB_Produtos do
  begin
    Close;
    IndexName := 'PorNome';
    Open;
    while not EOF do
    begin
      TC_Produtos.Tabs.Add(FieldByName('Desig').AsString);
      SL_Id_Produtos.Add(FieldByName('id_produto').AsString);
      Next;
    end;
    First;
  end;
end;

WHYYYYYYYYYYYYYYYYYYYYY?????????


i also need to know how to make this work:

     sql:= 'SELECT cod_forn,nome FROM fornecedores';
     sql:= sql + ' ORDER BY nome';
     Query1.SQL.Clear;
     Query1.SQL.Add(sql);
     Query1.ExecSQL;

     WHILE not F_Produtos.Query1.Fields[1].IsNull do
           begin
                C_F_Nome.Items.Add(Query1.Fields[1].AsString);
                query1.Fields.next;
           end;

and what if i wanted to use aquery that resides in another
active form to do this???


come on guys the questions are big but simple to answer!!
i know that and it´s what bother´s me the most
0
Comment
Question by:ElvasLion
[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
  • 7
  • 6
13 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 1385313
Here are the answers to the two questions:

1. The problem with the fill_tab procedure is that the tabcontrol is defined in the form, where as fill_tab is not.

You can either pass the tabcontrol to the fill_tab procedure like this:

procedure fill-tab(TC_produtos : TTabControl);

or define the fill_tab procedure as a method in the form

ie: procedure TForm1.fill_tab...
(Also place the declaration of fill_tab in the form class declaration, say in the protected or public sections.

2. Use Query1.Open instead of Query1.ExecSQL

Cheers,

Raymond.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385314
continuing...

3. WHILE not F_Produtos.Query1.Fields[1].IsNull do
     begin
      C_F_Nome.Items.Add(Query1.Fields[1].AsString);
      query1.Fields.next;
     end;

should look like this:

  WHILE not F_Produtos.Query1.EOF do
    begin
      C_F_Nome.Items.Add(Query1.Fields[1].AsString);
      query1.Fields.next;
    end;

4. You can do this:

   TheOtherForm.Query1.<whatever>

   Usually though you place queries, tables etc that are used in multiple places into a datamodule (the help has a good explanation and examples of these...

Cheers,

Raymond.
0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1385315
Raymond in 1 i need an example of the 2 ways to do it please short but with at least 2 parameters and the call line!
in 2 it say´s that it needs an [ next to query1.fields
and when i put it (query1.fields[1].next) it says no such identifier next
How woul´d you use a query to poppulate a combo?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385316
Elvas:

1. OK - assuming the parms a TTabControl and TTable, the fill_tab proc would look like this:

procedure fill_tab(TC_produtos : TTabControl;
                   TB_Produtos : TTable);
begin
...
end;

To call it:

fill_tab(TC_produtos, TB_Produtos); // Where these are elements of the form.

OR you just declare fill_tab as a method of the form:

(in the form declaration)
   protected
     procedure fill_tab(TC_produtos : TTabControl;
                        TB_Produtos : TTable);    
etc

(in the implementation)
procedure TForm1.fill_tab(TC_produtos : TTabControl;
                          TB_Produtos : TTable);

2. That should be Query.Next

Cheers,

Raymond.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385317
I think I showed you how to fill in a combo in another answer... anyway, you would do like this:

Query1.sql.clear;
Query1.sql.add('SQL to extract items');
Query.open
TheCombo.items.clear;
while not Query1.eof do
  begin
    TheCombo.items.add(query1.fieldsbyname['TheField']).AsString;
    query1.next;
  end;
0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1385318
as to the firs question i haven´t tryed it but i think i understand it.
in the second question, yes you told how to fill a combo, but that´s not the problem, because if you see the code i posted in the question you´ll se that it´s ok, the problem is that now i want to fill it from a query and it doesn´t work, i´ve already tryed that way before i posted the original question and it didn´t work, so please test you´re code and tell me if the problem is in my computer or tell me the way to really make it work.
sorry for the trouble, but i think that you can help me even more.
thañks for evrerything raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385319
Here is a snippet from an app of mine...

  DataModule1.SizeQuery.SQL.Clear;
  DataModule1.SizeQuery.SQL.add(format('Select * from %s_sizes where ID = "%s"',
                           [cmbCategory.Text, ID]));
  DataModule1.SizeQuery.Open;

  DataModule1.SizeQuery.First;
  fldSize := DataModule1.SizeQuery.FieldByName('ItemSize')

  repeat
    fSizes.Add(fldSize.AsString);
    QtyInStock := QtyInStock + fldSize.Value;

    DataModule1.SizeQuery.Next;
  until DataModule1.SizeQuery.Eof;

This should help...

Cheers,

Raymond.

0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1385320
I beleave that your answer woul´d help anyone, but i don´t know how to work with datamodules yet, and i don´t have time to learn it now.
my problem is that i load 2 field into the query, and in those 2 fields there is many data, i mean it maybe 500 ids and names, and i need all the names in the combo, and the ids in a stringlist that i have.
id-->   goes in query1.fields[0]
name--> goes in query1.fields[1]

i only need a way to know when the query reaches the end, so that i can stop.
please build a simple example and test it before you post because the first one you told me didn´t work.

thanks again, and sorry for the trouble
0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1385321
I managed to solve the problem by my own, but since you work so hard trying to answer my doubt i´ll give you the points, just tell me how can i call an event like this

T_Form1.TCombo1Change(Sender: TObject);
begin
   my code...
end;

now i want to call this from here

T_Form.TCombo2Change(Sender: TObject);
begin
   my code...
   combo1.onchange (how do i do this)
end;
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385322
Hi Elvas,

Both the code examples show how to stop when they reach the end of the records in the query  - thats what the Query1.EOF test is doing!

You can call events directly, rather than through the event property in the component:

T_Form.TCombo2Change(Sender: TObject);
begin
   my code...
   TCombo1Change(Sender);
end;

Cheers,

Raymond.

0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1385323
thank you once more raymond, but my problem is what is the sender and what do i write in it???
tcombo1change(???????);
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385324
Sender is the argument passed to TCombo2Change. Just use it as written.

In event handlers Sender is used to denote the object that generated the event. In this case, Sender will be the ComboBox that was changed...

Cheers,

Raymond.

0
 
LVL 1

Author Comment

by:ElvasLion
ID: 1385325
thank you very much raymond, you´ve been most helpfull!
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.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

715 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