AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi how to extract a list from a query to pass it to the next function
Thema durchsuchen
Ansicht
Themen-Optionen

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

Ein Thema von piedad · begonnen am 9. Jun 2020 · letzter Beitrag vom 18. Jun 2020
Antwort Antwort
piedad

Registriert seit: 5. Jun 2020
10 Beiträge
 
#1

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

  Alt 9. Jun 2020, 18:52
Datenbank: SQL • Version: QDA Version9 • Zugriff über: Delphi
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);
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.768 Beiträge
 
Delphi 10.4 Sydney
 
#2

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

  Alt 9. Jun 2020, 21:33
.. 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;
Klaus
  Mit Zitat antworten Zitat
piedad

Registriert seit: 5. Jun 2020
10 Beiträge
 
#3

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

  Alt 15. Jun 2020, 08:37
Hi Klaus thanks a lot, I still does not get working in this waymaybe another idea ?
Best regards Piedad
  Mit Zitat antworten Zitat
API

Registriert seit: 18. Apr 2004
637 Beiträge
 
#4

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

  Alt 15. Jun 2020, 10:50
FYI: There is an English version of Delphipraxis: http://en.delphipraxis.net/
  Mit Zitat antworten Zitat
Benutzerbild von Sinspin
Sinspin
Online

Registriert seit: 15. Sep 2008
Ort: Dubai
677 Beiträge
 
Delphi 10.3 Rio
 
#5

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

  Alt 15. Jun 2020, 15:54
FYI: There is an English version of Delphipraxis: http://en.delphipraxis.net/
...Which helps how to solve the problem?

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
Stefan
Nur die Besten sterben jung
A constant is a constant until it change.
  Mit Zitat antworten Zitat
API

Registriert seit: 18. Apr 2004
637 Beiträge
 
#6

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

  Alt 15. Jun 2020, 19:52
...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..
  Mit Zitat antworten Zitat
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.275 Beiträge
 
Delphi 10.4 Sydney
 
#7

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

  Alt 15. Jun 2020, 21:34
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);
Heiko
  Mit Zitat antworten Zitat
piedad

Registriert seit: 5. Jun 2020
10 Beiträge
 
#8

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

  Alt 16. Jun 2020, 01:09
thank you hoika, that was really what I was Looking for.
  Mit Zitat antworten Zitat
piedad

Registriert seit: 5. Jun 2020
10 Beiträge
 
#9

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

  Alt 18. Jun 2020, 01:36
FYI: There is an English version of Delphipraxis: http://en.delphipraxis.net/
...Which helps how to solve the problem?

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
  Mit Zitat antworten Zitat
Antwort Antwort

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:19 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