Link to home
Start Free TrialLog in
Avatar of erichuang
erichuang

asked on

i want to change the c++ code to delphi code!

I write a bc++ code :
void __fastcall TForm1::FormCreate(TObject *Sender)
{





 while(!Query1->Eof)
  {
      char szName[255];
      // get data from first table
      // and save data into csc
      String csc = Query1->FindField("STKCODE")->AsString;
      String mkt = Query1->FindField("MKT")->AsString;
      // into csc to second table and get data

      if(mkt == "TSE"){
      Query2->Close();

      Query2->SQL->Clear();
      Query2->SQL->Add("select stkcode,syear*100+smon,sb_vol,lb_vol/100,cp");
      Query2->SQL->Add("from ap.amgin");
      Query2->SQL->Add("where STKCODE =:sss");
      Query2->SQL->Add("and syear*100+smon >199702");
      Query2->ParamByName("sss")->AsString= csc;
      Query2->Active=TRUE;

     // use the data of second table to draw the line chart
      Series1->DataSource=Query2;
      Series1->ParentChart=DBChart1;
      Series1->XLabelsSource="syear*100+smon";
      Series1->YValues->ValueSource= "lb_vol/100";
      Series2->DataSource=Query2;
      Series2->ParentChart=DBChart1;
      Series2->XLabelsSource="syear*100+smon";
      Series2->YValues->ValueSource= "sb_vol";
      Series3->DataSource=Query2;
      Series3->ParentChart=DBChart1;
      Series3->XLabelsSource="syear*100+smon";
      Series3->YValues->ValueSource= "cp";
      wsprintf(szName,"c:\\gmgin\\gmgintse%s.bmp",csc);
      DBChart1->SaveToBitmapFile(szName);
      Query1->Next();
      }
      else{
       Query2->Close();

      Query2->SQL->Clear();
      Query2->SQL->Add("select stkcode,syear*100+smon,sb_vol,lb_vol/100,cp");
      Query2->SQL->Add("from ap.amgin");
      Query2->SQL->Add("where STKCODE =:sss");
      Query2->SQL->Add("and syear*100+smon >199702");
      Query2->ParamByName("sss")->AsString= csc;
      Query2->Active=TRUE;

     // use the data of second table to draw the line chart
      Series1->DataSource=Query2;
      Series1->ParentChart=DBChart1;
      Series1->XLabelsSource="syear*100+smon";
      Series1->YValues->ValueSource= "lb_vol/100";
      Series2->DataSource=Query2;
      Series2->ParentChart=DBChart1;
      Series2->XLabelsSource="syear*100+smon";
      Series2->YValues->ValueSource= "sb_vol";
      Series3->DataSource=Query2;
      Series3->ParentChart=DBChart1;
      Series3->XLabelsSource="syear*100+smon";
      Series3->YValues->ValueSource= "cp";
      wsprintf(szName,"c:\\gmgin\\gmginotc%s.bmp",csc);
      DBChart1->SaveToBitmapFile(szName);
      Query1->Next();
      }

 }

}


now i want to change to the delphi code
but Have a lot of error .
how will i change!
the delphi code :
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, Db, DBTables, ExtCtrls, TeeProcs, TeEngine, Chart,
  DBChart, StdCtrls, Series;

type
  TForm1 = class(TForm)
    DBChart1: TDBChart;
    Query1: TQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    Query2: TQuery;
    DataSource2: TDataSource;
    DBGrid2: TDBGrid;
    Series1: TLineSeries;
    Series2: TLineSeries;
    Query3: TQuery;
    DataSource3: TDataSource;
    Query4: TQuery;
    DataSource4: TDataSource;
    DBGrid3: TDBGrid;
    DBGrid4: TDBGrid;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.FormCreate(Sender: TObject);
// var szName:array[0..255] of char;
var ind_tek,mkt:string;
begin

     while Query1.Eof <> true  do
     begin
          ind_tek := Query1.FindField('STKCODE').AsString;
          mkt :=Query1.FindField('MKT').AsString;
          Edit1.Text := mkt;
          if mkt=('TSE')
          then

                 Query2.Close();
                 Query2.SQL.Clear();
                 Query2.SQL.Add('select syear*100+smon,cp');
                 Query2.SQL.Add('from ap.aprcm');
                 Query2.SQL.Add('where stkcode = :mem');
                 Query2.SQL.Add('and (syear*100+smon)>199702');
                 Query2.ParamByName('mem').AsString := ind_tek;
                 Query2.Active :=TRUE;


           Series1.DataSource:=Query2;
           Series1.ParentChart:=DBChart1;
           Series1.XLabelsSource:='syear*100+smon';
           Series1.YValues.ValueSource := 'cp';
           Series2.DataSource:=Query3;
           Series2.ParentChart:=DBChart1;
           Series2.XLabelsSource:='syear*100+smon';
           Series2.YValues.ValueSource := 'cp';

           // wsprintf(szName,'e:\\gprcm\\gprcm%s.bmp',ind_stk);
           DBChart1.SaveToBitmapFile('e:\\gprcm\\gprcm'+'ind_stk'+'.bmp');
           Query1.Next();
           END

         else
           begin
      Query2.Close();
      Query2.SQL.Clear();
      Query2.SQL.Add("select syear*100+smon,cp");
      Query2.SQL.Add("from ap.aprcm");
      Query2.SQL.Add("where stkcode=:mem");
      Query2.SQL.Add("and syear*100+smon>199702");
      Query2.ParamByName("mem").AsString:=ind_stk;
      // Query2->Prepare();
      Query2->Active = TRUE;

      Series1.DataSource:=Query2;
      Series1.ParentChart:=DBChart1;
      Series1.XLabelsSource:='syear*100+smon';
      Series1.YValues.ValueSource := 'cp';
      Series2.DataSource:=Query4;
      Series2.ParentChart:=DBChart1;
      Series2.XLabelsSource:='syear*100+smon';
      Series2.YValues.ValueSource := "cp";

      // wsprintf(szName,'e:\\gprcm\\gprcmotc%s.bmp',ind_stk);
      // DBChart1.SaveToBitmapFile(szName);
      Query1.Next();
      end


end;

end.
thanks for your help
             eric
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of erichuang
erichuang

ASKER

thanks for your help.
i will try your suggest after few day.
thanks,
             eric