Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi how to extract a list from a query to pass it to the next function (https://www.delphipraxis.net/204591-how-extract-list-query-pass-next-function.html)

piedad 9. Jun 2020 17:52

Datenbank: SQL • Version: QDA Version9 • Zugriff über: Delphi

how to extract a list from a query to pass it to the next function
 
Hi Guys,
I am fighting with a piece of Code and can not move Forwards, do you a have a hint for a Delphi SQL beginner?

I want to extract a list of names from a Database for making a return in my function and after that passing that to another function in my big program.
1. I tried following Code making a big program and I got my csv table with the column of names, but if I try to separate my big program in Little modules, it does not work any more
I got by Debugging a run time error E/AFehler 103 when evaluating the instruction PushVar($0,$0,0,$0,$0,'Result'9. in the Position: (***)
I am sure it is a very stupid Thing, but I cannot catch it now.
2. it is possible to Export this Little query to assign it to my fn1 result for passing this value to the function fn2?
thnaks a lot in Advance and Kind regards
Piedad


function fn1:String;
var
...
qryPMV := TQuery.Create(nil);
tsSQLListe := TStringList.create;

qryPMV.DatabaseName := 'DB';
qryPMV.Close;
qryPMV.Sql.Clear;

qryPMV.Sql.Add('SELECT Distinct column1 PMV ');
qryPMV.Sql.Add('FROM MMV_DB ');
qryPMV.Sql.Add('Order by PMV ');
strSQL := qryPMV.Sql.GetText;
qryPMV.Open;


if not (qryPMV.bof and qryPMV.eof) then
begin

strHeader := 'PM_guys';
Writeln(tfFilePointer, strHeader); (***)

WHILE not qryPMV.EOF do
begin
strOutputZeile := '';
tsSQLListe.Add(cTrenner + qryPMV.FieldByName('PM_VERANTWORTLICHER').AsString );
strPPV := StringReplace(tsSQLListe.text, cCRLF, cDelimiter, 1);
strOutputZeile := strPPV;

tsSQLListe.Clear;
Writeln(tfFilePointer, strOutputZeile);
qryPMV.next;

end;
end;

CloseFile(tfFilePointer);

Klaus01 9. Jun 2020 20:33

AW: how to extract a list from a query to pass it to the next function
 
.. maybe it will work in that way

Best regards
Klaus

Delphi-Quellcode:
procedure fn1(var sl:TStringList);
var
...
qryPMV := TQuery.Create(nil);

qryPMV.DatabaseName := 'DB';
qryPMV.Close;
qryPMV.Sql.Clear;

qryPMV.Sql.Add('SELECT Distinct column1 PMV ');
qryPMV.Sql.Add('FROM MMV_DB ');
qryPMV.Sql.Add('Order by PMV ');
strSQL := qryPMV.Sql.GetText;
qryPMV.Open;


if not (qryPMV.bof and qryPMV.eof) then
  begin
    strHeader := 'PM_guys';
    WHILE not qryPMV.EOF do
      begin
        strOutputZeile := '';
        strPPV := strHeader + cTrenner + qryPMV.FieldByName('PM_VERANTWORTLICHER').AsString;
        strPPV := StringReplace(strPPV, cCRLF, cDelimiter, 1);
        sl.add(strPPV);
        qryPMV.next;
      end;
end;

piedad 15. Jun 2020 07:37

AW: how to extract a list from a query to pass it to the next function
 
Hi Klaus thanks a lot, I still does not get working in this waymaybe another idea ?
Best regards Piedad

API 15. Jun 2020 09:50

AW: how to extract a list from a query to pass it to the next function
 
FYI: There is an English version of Delphipraxis: http://en.delphipraxis.net/

Sinspin 15. Jun 2020 14:54

AW: how to extract a list from a query to pass it to the next function
 
Zitat:

Zitat von API (Beitrag 1467295)
FYI: There is an English version of Delphipraxis: http://en.delphipraxis.net/

...Which helps how to solve the problem?

Zitat:

Zitat von piedad (Beitrag 1467274)
Hi Klaus thanks a lot, I still does not get working in this waymaybe another idea ?

Please can you explain what is not working?
Any error message?
Any result which you get which looks not as expected?

I still don't understand what the TStringlist is for and why the "tfFilePointer"?

Btw. It is interesting that you write in english, but some parts of the source code are german ;-)

API 15. Jun 2020 18:52

AW: how to extract a list from a query to pass it to the next function
 
Zitat:

Zitat von Sinspin (Beitrag 1467348)
...Which helps how to solve the problem?


This was simply a hint that there is an English version of DP and that not everybody can/will answer in English here..

hoika 15. Jun 2020 20:34

AW: how to extract a list from a query to pass it to the next function
 
Hello,
Zitat:

another idea
Why?

Your code is almost ready.

create a StringList, put it as a parameter to your submethod und replace the following in your submethod

Writeln(tfFilePointer, strOutputZeile);
with
StringlistParam.Add(strOutputZeile);

piedad 16. Jun 2020 00:09

AW: how to extract a list from a query to pass it to the next function
 
thank you hoika, that was really what I was Looking for.

piedad 18. Jun 2020 00:36

AW: how to extract a list from a query to pass it to the next function
 
Zitat:

Zitat von Sinspin (Beitrag 1467348)
Zitat:

Zitat von API (Beitrag 1467295)
FYI: There is an English version of Delphipraxis: http://en.delphipraxis.net/

...Which helps how to solve the problem?

Zitat:

Zitat von piedad (Beitrag 1467274)
Hi Klaus thanks a lot, I still does not get working in this waymaybe another idea ?

Please can you explain what is not working?
Any error message?
Any result which you get which looks not as expected?

I still don't understand what the TStringlist is for and why the "tfFilePointer"?

Btw. It is interesting that you write in english, but some parts of the source code are german ;-)

If you knew, I am from spain but Living in Germany :~)
I have to check it again


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:24 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz