線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2035
推到 Plurk!
推到 Facebook!

請問如何把Delphi .pas轉成BCB6 .cpp

尚未結案
myboss
一般會員


發表:25
回覆:42
積分:13
註冊:2004-01-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-11 10:53:14 IP:218.163.xxx.xxx 未訂閱
請問諸位先進,由於公司要求,需要一個可資料感知之Datetimepicker 上Delphi深度歷險找到一個ALDate元件,可是不懂得如何模仿修改成BCB6版
ALDate.pas內容如下
unit ALDate;    { This class is inherithed from TDataTimePicker and link to a table.
In addition to component original there are two additional properties:
Datasource and Datafield    Alejandro Castro
calfra@mail.internet.com.mx    }    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls,DB,DBCtrls;    type
  TALDate = class(TDateTimePicker)
  private
    FReadOnly : Boolean;
    FDataLink: TFieldDataLink;
    function GetDataField: string;
    function GetDataSource: TDataSource;
    procedure SetDataField(const Value : string);
    procedure SetDataSource(Value: TDatasource);
    procedure DataChange(Sender: TObject);
    procedure UpdateData(Sender: TObject);
    procedure Change(Sender: TObject);
    procedure CMExit (var Message: TWMNoParams); message CM_EXIT;
  protected
    procedure KeyDown ( var Key: word; shift: TShiftState); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property ReadOnly : Boolean read FReadOnly write FreadOnly default false;
    property DataField: string read GetDataField write SetDataField;
    property DataSource: TDataSource read GetDataSource write SetDataSource;      end;    procedure Register;    implementation    procedure Register;
begin
  RegisterComponents('Alfra', [TALDate]);
end;    constructor TALDate.Create(AOwner: TComponent);
begin
  inherited create(AOwner);
  FReadOnly:=false;
  OnChange:=Change;
  FDataLink:=TFieldDataLink.Create;
  FDataLink.OnDataChange:=DataChange;
  FDataLink.OnUpdateData := UpdateData;    end;    destructor TALDate.Destroy;
begin
  FDataLink.OnDataChange:=nil;
  FDataLink.Free;
  inherited Destroy;
end;    function TALDate.GetDataField: string;
begin
  Result:=FDataLink.fieldname;
end;    function TALDate.GetDataSource:TDataSource;
begin
  Result:=FDataLink.DataSource;
end;    Procedure TALDate.SetDataField(const value: string);
begin
  FDataLink.FieldName:=Value;
end;    procedure TALDate.SetDataSource(Value: TDataSource);
begin
  FDataLink.DataSource:=Value;
end;    procedure TALDate.DataChange(Sender: TObject);
begin
  if FDataLink.field = nil then
    date :=0
  else
{    if not (FDatalink.DataSource.State in [dsInsert]) then}
      Date:=FDatalink.field.AsDateTime ;
end;    procedure TALDate.UpdateData(Sender: TObject);
begin
  if FDataLink.CanModify then
    FDataLink.Field.AsDateTime:=Date;
end;    procedure TALDate.Change;
begin
  FDataLink.modified;
  inherited;
end;    procedure TALDate.KeyDown(var Key: word; Shift:TshiftState);
var
  MyKeyDown: TKeyEvent;
begin
  if not ReadOnly and (key in [VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_END,
    VK_HOME, VK_PRIOR, VK_NEXT]) and FDataLink.Edit then
    inherited KeyDown(Key,Shift)
  else
  begin
    MyKeyDown:=OnKeyDown;
    if Assigned(MyKeyDown) then MyKeyDown(Self, Key, Shift);
  end;
end;    procedure TALDate.CMExit(Var Message: TWMNoParams);
begin
  try
    FdataLink.UpdateRecord;
  except
    on Exception do SetFocus;
  end;
  inherited;
end;    end.    我試著依照內容寫成BCB6版,還沒寫入CPP就有20個Error    #ifndef ALDateH
#define ALDateH
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include 
#include 
#include 
   //E2209 Unable to open include file 'DBCtrl.hpp'
#include 
#include 
#include 
#include <Forms.hpp>
#include 
#include 
//---------------------------------------------------------------------------
class PACKAGE TALDate : public TDateTimePicker
{
private:
        bool FReadOnly;
        TFieldDataLink FDataLink;
            //E2303 Type name expected   E2139 Declaration missing ;
        String GetDataField();
        TDataSource GetDataSource();
        void __fastcall SetDataField(String *Value);
        void __fastcall SetDataSource(TDatasource *Value);
           //E2293 ) expected
        void __fastcall DataChange(TObject *Sender);
        void __fastcall UpdateData(TObject *Sender);
        void __fastcall Change(TObject * Sender);
        void __fastcall CMExit(TWMNoParams * Message);
protected:
        void __fastcall KeyDown (WORD &Key;TShiftState Shift);
           //E2293 ) expected   E2139 Declaration missing ;
        BEGIN_MESSAGE_MAP
                VCL_MESSAGE_HANDLER(CMExit, TWMNoParams *, CMExit)
        END_MESSAGE_MAP(TDateTimePicker)
public:
        void __fastcall TALDate(TComponent* Owner);
           //E2136 Constructor cannot have a return type specification
        __fastcall ~TALDate();
__published:
        __property bool ReadOnly  = { read=FReadOnly, write=FReadOnly, default=false };
        __property String DataField  = { read=GetDataField, write=SetDataField };
          //E2347 Parameter mismatch in write access specifier of property DataField
        __property TDataSource * DataSource  = { read=GetDataSource, write=SetDataSource };    /*         E2316 'SetDataSource' is not a member of 'TALDate'
  [C   Error] ALDate.h(42): E2008 Published property access functions must use __fastcall calling convention
  [C   Error] ALDate.h(43): E2008 Published property access functions must use __fastcall calling convention
  [C   Warning] ALDate.h(44): W8022 '_fastcall TALDate::Change(TObject *)' hides virtual function '_fastcall TDateTimePicker::Change()'
  [C   Error] ALDate.h(35): E2313 Constant expression required
  [C   Error] ALDate.cpp(22): E2451 Undefined symbol 'TALDate'
  [C   Error] ALDate.cpp(22): E2451 Undefined symbol 'AOwner'
  [C   Warning] ALDate.cpp(39): W8070 Function should return a value
  [C   Warning] ALDate.cpp(44): W8070 Function should return a value
  [C   Error] ALDate.cpp(47): E2316 '_fastcall TALDate::SetDataField(AnsiString *)' is not a member of 'TALDate'
  [C   Error] ALDate.cpp(51): E2147 'TDatasource' cannot start a parameter declaration
  [C   Error] ALDate.cpp(52): E2316 '_fastcall TALDate::SetDataSource(int *)' is not a member of 'TALDate'
  [C   Error] ALDate.cpp(62): E2316 '_fastcall TALDate::UpdateData(TObject *)' is not a member of 'TALDate'
  [C   Error] ALDate.cpp(77): E2451 Undefined symbol 'WORD'
  [C   Error] ALDate.cpp(77): E2141 Declaration syntax error
*/
};
//---------------------------------------------------------------------------
#en
請問究竟我該怎麼改? 發表人 - taishyang 於 2004/05/11 13:15:12
anpino
版主


發表:31
回覆:477
積分:231
註冊:2003-01-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-12 09:10:10 IP:211.23.xxx.xxx 未訂閱
#ifndef ALDateH
#define ALDateH
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include 
#include 
#include s.hpp>
#include 
#include 
#include 
#include <Forms.hpp>
#include 
#include 
//---------------------------------------------------------------------------
class PACKAGE TALDate : public TDateTimePicker
{
private:
        bool FReadOnly;
        TFieldDataLink *FDataLink;
        String GetDataField();
        TDataSource GetDataSource();
        void __fastcall SetDataField(String Value);
        void __fastcall SetDataSource(TDatasource *Value);
        void __fastcall DataChange(TObject *Sender);
        void __fastcall UpdateData(TObject *Sender);
        void __fastcall Change(TObject * Sender);
        void __fastcall CMExit(TWMNoParams * Message);
protected:
        void __fastcall KeyDown (WORD &Key,TShiftState Shift);
        //或
        //DYNAMIC void __fastcall KeyDown(Word &Key, Classes::TShiftState Shift);
        BEGIN_MESSAGE_MAP
                VCL_MESSAGE_HANDLER(CMExit, TWMNoParams *, CMExit)
        END_MESSAGE_MAP(TDateTimePicker)
public:
        __fastcall TALDate(TComponent* Owner);
        __fastcall ~TALDate();
__published:
        __property bool ReadOnly  = { read=FReadOnly, write=FReadOnly, default=false };
        __property String DataField  = { read=GetDataField, write=SetDataField };
        __property TDataSource * DataSource  = { read=GetDataSource, write=SetDataSource };    };
//---------------------------------------------------------------------------
#enif    以上, 只是用"目視"看出來要改的地方。
請參考。    
------------------------------- 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D ------------------------------- 發表人 - anpino 於 2004/05/12 09:35:50
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-12 10:37:05 IP:147.8.xxx.xxx 未訂閱
Just wondering.... BCB can use most VCL components written in Delphi becasue it can compile Object Pascal codes... Perhaps you should give it a try...
myboss
一般會員


發表:25
回覆:42
積分:13
註冊:2004-01-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-05-12 17:07:46 IP:218.163.xxx.xxx 未訂閱
謝謝anpino兄的告知,我因而少了4個錯誤, 另外請問william兄如何在BCB6中用Delphi之元件? 還有這樣會不會牽涉到版權問題?
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-05-13 09:41:06 IP:147.8.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/topic.php?topic_id=26857 Of course you need to check the license of your components (e.g. readme, help, etc.).
myboss
一般會員


發表:25
回覆:42
積分:13
註冊:2004-01-13

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-05-14 12:46:13 IP:218.163.xxx.xxx 未訂閱
謝謝William 兄的告知,可惜Compiles時還是有2個Error 另外想請問該去哪尋找 LIBRARIES 以及 SPARELIBS 這兩個標記 [Pascal Error] ALdate.pas(111): Incompatible types [Pascal Fatal Error] pasall.tmp(3): Could not compile used unit 'C:\Program Files\Borland\CBuilder6\Lib\ALdate.pas' 發表人 - myboss 於 2004/05/14 12:48:38
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-05-14 14:48:55 IP:147.8.xxx.xxx 未訂閱
Line 111? Which line exactly?
lijenyun
一般會員


發表:3
回覆:19
積分:9
註冊:2003-06-22

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-05-14 21:40:10 IP:203.73.xxx.xxx 未訂閱
原始碼可能有誤 Change 要改名,如 ChangeDate 
procedure TALDate.Change; ->改為procedure ChangeDate(Sender: TObject);以免和父類別衝突
begin
  FDataLink.modified;
  inherited; ->這一行改為Change; (檢查TDateTimePicker的 Change 方法宣告為 dynamic; 而不是virtual那來的inherited)
end;
myboss
一般會員


發表:25
回覆:42
積分:13
註冊:2004-01-13

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-05-15 10:54:06 IP:218.163.xxx.xxx 未訂閱
William兄你好: Line 111正是lijenyun兄所修正之地方,lijenyun兄果然功力高強。 procedure TALDate.Change; ->改為procedure ChangeDate(Sender: TObject);以免和父類別衝突 begin FDataLink.modified; inherited; ->這一行改為Change; (檢查TDateTimePicker的 Change 方法宣告為 dynamic; 而不是virtual那來的inherited) end; 只是元件此時雖然可以Compile & Install 但卻無法使用,出現下列之錯誤訊息: [C Error] buObt.h(56): E2303 Type name expected [C Error] buObt.h(56): E2139 Declaration missing ; [C Error] buObt.h(56): E2109 Not an allowed type 經檢視原始碼,Line 56: TALDate *ALDate1; 也就是說,元件可以安裝卻無法使用,請問這是怎麼回事?
lijenyun
一般會員


發表:3
回覆:19
積分:9
註冊:2003-06-22

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-05-16 09:03:52 IP:210.244.xxx.xxx 未訂閱
在我的BCB4上沒有問題,請其他高手釋疑 (LIBRARIES 以及 SPARELIBS 這兩個標記在你的???.bpk檔) 發表人 - lijenyun 於 2004/05/16 09:09:41
myboss
一般會員


發表:25
回覆:42
積分:13
註冊:2004-01-13

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-05-16 11:51:51 IP:218.163.xxx.xxx 未訂閱
lijenyun兄你好: 這一題應該是要給你得分的,只是不小心轉了 一下滑鼠滾輪,把分數給了William兄,雖然William兄 的回答也很夠力,但是這元件能用您功不可沒也。
lijenyun
一般會員


發表:3
回覆:19
積分:9
註冊:2003-06-22

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-05-16 20:15:57 IP:210.68.xxx.xxx 未訂閱
No,我也是照william兄的方向去測試罷了 由william兄得分當之無愧
系統時間:2024-07-04 8:40:22
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!