ich habe jetzt noch ein anders Problem an dem ich scheitere:
folgende Situation: 
- ich habe eine Unit_1 mit TForm1 -> mit Connect zu einer DB + SQL-Query + Dataset + xxx
- ich habe eine Unit_2 mit einer Klasse die in die Unit_1 eingebunden ist
- jetzt möchte ich in der Unit_2 ein SQL-Query absetzten mit der DB-Connection aus Unit_1 - das bekomme ich nicht hin   Problem_1 gelöst
-  Problem_2 sind die Pointer... in welcher Rehenfolge man die setzt
Code: Alles auswählen
 
unit piedit;
 
{$mode objfpc}{$H+}
 
interface
 
uses
  x,y,z,
  piHistory,pi_value;
 
type
 
  { TForm1 }
 
  TForm1 = class(TForm)
          .
    piDataSource: TDataSource;
    pi_connect: TZConnection;
    piQuery: TZQuery;
    PIHistory : TPIHistory;
          .
  private
          .
    procedure GetTable;
          . 
  public
 
implementation
 
procedure TForm1.GetTable;
var 
  xy...
  historydata : T_valueHistory;
begin
  if not piQuery.IsEmpty then
  begin
    piGrid_Data.Open;
   //fülle Listen u.s.w.
    while not piQuery.EOF do
    begin
      if cb_History.Checked then
        // gehe in Unit piHistory und fülle <historydata>  -> Liste
        //historydata ist ein Pointer in QT3
        //PIHistory.setValue(&historydata, sval.VALUE_ID); QT3
        //historydata wird später gebraucht um ein GRID zu füllen
        PIHistory.setValue(historydata,sval.VALUE_ID);
    end;
   PIHistory.Load
  end;
end;
 
Code: Alles auswählen
 
unit piHistory;
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, fgl, ZDataset,
  pi_value;
 
type
  TPIHistory = Class
    public
      Tvaluestack   : T_valuestack;
      TvalueHistory : T_valueHistory;
      procedure run;
      procedure setValue(var historydata : T_valueHistory; Design : String);
      procedure Load;
    private
      m_phistorydata : ^T_valueHistory; //Problem_2
      m_pDesign : TStringList;
      m_ValueID : String;
      piQuery_history : TZQuery;
  end;
 
implementation
//Problem_1 gelöst
uses
  piedit;
 
procedure TPIHistory.run;
begin
  Load;
end;
 
procedure TPIHistory.Load;
var
  vString : String;
  s_it    : String;
  i       : Integer;
  item    : TPI_SingleValueHistory;
  hline   : T_valuestack;
begin
  for i:=0 to m_pDesign.Count -1 do
  begin
    hline := T_valuestack.Create(false);
    item  := TPI_SingleValueHistory.Create;
    m_ValueID := m_pDesign[i];
    vString := ' SELECT H.FK_VALUE_ID, V.FK_DESIGN_ID, H.VALUE, H.FK_FORMAT_ID, H.DATE_TIME, U.NAME  FROM PI_VALUE V, PI_HISTORY H, USER_NAMES U WHERE H.FK_VALUE_ID =' + m_ValueID + ' AND H.FK_VALUE_ID = V.VALUE_ID AND H.FK_USER_ID = U.USER_ID ORDER BY HISTORY_ID DESC';
 
    piQuery_history.SQL.Text:=vString;
    piQuery_history.Connection:=Form1.pi_connect;
    piQuery_history.Open;
 
    if not piQuery_history.IsEmpty then
    begin
      while not piQuery_history.EOF do
      begin
        item.FK_FORMAT_ID:='23456';
        item.VALUE:='test';
        item.DESIGN_ID:='344556';
        item.VALUE_ID:='344667';
        hline.Add(item);
        //fülle Liste
        m_phistorydata^.Add(piQuery_history.Fields[0].AsInteger,hline);
      end;
    end;
  end;
end;
 
// set history values
procedure TPIHistory.setValue(var historydata : T_valueHistory; Design : String);
begin
  m_pDesign := TStringList.Create();
  m_phistorydata^ := T_valueHistory.Create;  //ERROR????? Problem_2
  m_phistorydata := @historydata;            //????? Problem_2
  m_pDesign.Add(Design);
  m_ValueID := Design;
end;
 
end.
 
Code: Alles auswählen
 
unit pi_value;
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, fgl;
 
type
  TPI_SingleValue = class
    VALUE        : String;
    DESIGN_ID    : String;
    FK_FORMAT_ID : String;
    VALUE_ID     : String;
    constructor Create;
    destructor Destroy; override;
  end;
 
  TPI_SingleValueHistory = class(TPI_SingleValue)
    DATE : String;
    USER : String;
  end;
 
  T_valuestack   = specialize TFPGObjectList<TPI_SingleValueHistory>;
  T_valueHistory = specialize TFPGMap<integer, T_valuestack>;
 
implementation
 
  constructor TPI_SingleValue.Create;
  begin
    inherited;
    TPI_SingleValue.Create;
  end;
 
  destructor TPI_SingleValue.Destroy;
  begin
    FreeAndNil(Self);
    inherited;
  end;
 
end.
 
QT3 cpp
Code: Alles auswählen
 
----header von CPIHistory-----
class CPIHistory : public QThread
{
public:
   // CPI_SingleValueHistory <->TPI_SingleValueHistory
    typedef Q3ValueList <CPI_SingleValueHistory> _valuestack;
    typedef QMap <int, _valuestack> _valueHistory;
    CPIHistory();
    ~CPIHistory();
    void run();
    void setValue(_valueHistory * historydata, QString  Design);
    void Load();
private:
    QMutex m_mutex;
 
    _valueHistory * m_phistorydata;
    QStringList m_pDesign;
    QString m_ValueID;
};
 
-------cpp-------
void CPIHistory::setValue(_valueHistory * historydata , QString  value_id)
{
    QMutexLocker locker( &m_mutex );
    m_phistorydata = historydata;
    m_pDesign.push_back(value_id);
    m_ValueID  = value_id;
}
 
void CPIHistory::Load()
{
        .
        .
       while ( query.next() )
		{
		//    qDebug("history "+ vString);		    
		    _valuestack hline;
		    _valueHistory::Iterator hline_it = m_phistorydata->find( m_pDesign.first().toInt() );
 
		    if( hline_it != m_phistorydata->end() )
		    {
			hline = (*hline_it);
		    }
 
		    CPI_SingleValueHistory  item;
 
		    item.VALUE = query.value(2).toString();
		    item.DESIGN_ID = query.value(1).toString();
		    item.FK_FORMAT_ID = query.value(3).toString();
		    item.VALUE_ID = query.value(0).toString();
		    item.DATE = query.value(4).toString();
		    item.USER = query.value(5).toString();
 
		    hline.push_back(item);
		    m_phistorydata->insert(query.value(0).toInt(), hline);
		}
 
		m_pDesign.pop_front();
}
Fazit: ich bin mit meinem freepascal Latein am Ende  
 
   
   
  