delphi代码转成c++builder

2025-03-01 22:10:34
推荐回答(3个)
回答1:

Delph和BCB虽是一个公司,同为VCL框架,但是毕竟是两种语言,不会像楼上说的.换成->就可以的.
现假设楼主有一定的C++基础,能使用基本的BCB6,改写如下:
1.新建一新工程,加入一Memo和一Button,控件Name为Memo1和Button1(即默认的名字)
2.向Memo1中加入任意内容,双击Button1产生单击事件
3.加入如下代码:
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void txttojpeg(TMemo* Memo1,AnsiString filename,TColor brush_color,TFont* font,TColor font_color,int width, int height)
{
Graphics::TBitmap *temp=new Graphics::TBitmap();
temp->Height=height;
temp->Width=width;
temp->Transparent=true;
temp->Canvas->Brush->Color=brush_color;
temp->Canvas->Font=font;
temp->Canvas->Font->Color=font_color;

int i=0,j=0;
for (i=0;iLines->Count;i++){
j = j + 15;
temp->Canvas->TextOutA(10,j,Memo1->Lines->Strings[i]);
}
temp->SaveToFile(filename);
delete temp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
txttojpeg(Memo1 ,"12.bmp", clWhite, Memo1->Font, clBlack, Memo1->Width, Memo1->Height);
}
//---------------------------------------------------------------------------
4.代码中重复的可省略,程序在BCB6 SP4下编译运行通过

回答2:

都是一个公司的产品,他们生成的dcu文件可以通用。

回答3:

这个好像不涉及到算法的东西啊,连类名称都不用换了。
把.换成->
:=换成=就行了