1.delphi的socke如果两段数据发送太快接收方会出现粘连在一起的情况,又同VB一样?应如何避免?如何解决?
2.DELPHI竟是单线程(与vb一样?)
例如:假设有一timer值为1000(1秒),默认enable为false,在timer的onTime添加事件如下
timer.tag:=1;
添加一按钮事件如下:
timer.enable:=true;
while timer.tag=0 do
begin end;
close;
则窗口永远不会关闭
那delphi有没有同vb功能类似的DoEvents函数呢?3.动态创建出一系列按钮元件如何在onClick事件中分别识别它们?
4.ComboBoxEx的默认图象如何设置?(当没有选它时出现在当前框中的图像)
5.如何获得MainMenu中的canvas?!
6.如何EXE正在运行时修改EXE本身?
7.举一个DDE会话的小例子?
2.DELPHI竟是单线程(与vb一样?)
例如:假设有一timer值为1000(1秒),默认enable为false,在timer的onTime添加事件如下
timer.tag:=1;
添加一按钮事件如下:
timer.enable:=true;
while timer.tag=0 do
begin end;
close;
则窗口永远不会关闭
那delphi有没有同vb功能类似的DoEvents函数呢?3.动态创建出一系列按钮元件如何在onClick事件中分别识别它们?
4.ComboBoxEx的默认图象如何设置?(当没有选它时出现在当前框中的图像)
5.如何获得MainMenu中的canvas?!
6.如何EXE正在运行时修改EXE本身?
7.举一个DDE会话的小例子?
解决方案 »
- VC++ 程序翻译到D7的问题
- 如何才能把一条dbgrid内得记录传到另一个form内呢?请高手指导!在线等啊!
- 一個沒入門的XML問題
- fastreport 的报表问题
- Delphi控件可以转成ActiveX控件吗? 高分向赠.
- HOW TO PASS four 怎么得的4星
- 为什么我添加一条记录成功后还报错:“ADODataSet: DataSet not in edit or insert mode”??怎么回事啊!
- MIDAS应用中能不能在客户端用TClientDataSet(或其他组件)发送sql语句得到数据?
- 当在easyGrid或stringGrid中选择一个单元格时,会有一个黑边框,如何去除这个边框呢?
- 求一个语句累加的问题
- 算法求救!!!!高手帮忙阿……
- 很菜的问题:如何简单的显示一个整型变量的值?
Button1.tag:=1;
Button1.OnClick:=Button1Click;
Button2:=TButton.Create(Self);
Button2.Tag:=2;
Button2.OnClick:=Button1Click;procedure TForm1.Button1Click(Sender:TObject);
begin
case TButton(Sender).Tag
1:...
2:...
end;
end;
如果要改变MainMenu 的默认效果,可以 MainMenu.OwnerDraw:=True;
然后在 菜单项 的 OnMeasureItem、 OnDrawItem 事件中处理
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,Math;type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Menu1: TMenuItem;
Menu2: TMenuItem;
procedure Menu1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
Selected: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;resourcestring
FlowerSoftWareStudio='Flower Software Studio';
FlowerSoftware='Flower Software';
FlowerSoft='FlowerSoft';
Flower='Flower';implementation{$R *.dfm}
var
MenuBackground:TBitmap;
MenuOffset:Integer;
blnMenuRefresh:Boolean;type
TArtRectMode=(armHorizontal,armVertical,armRectangle,armEllipse);
procedure DrawArtRect(ACanvas:TCanvas;ARect:TRect;ColorFrom,ColorTo:TColor;
ArtRectMode:TArtRectMode;Supplement:Integer=100);
var
Bmp:TBitmap;
i,n:Integer;
r1,g1,b1,r2,g2,b2:Integer;
r,g,b:Integer;
dr,dg,db,nr,ng,nb:Extended;
YXScale,f:Double;
OldColor:TColor;
begin
OldColor:=-1;
Bmp:=TBitmap.Create;
with Bmp do
begin
Width:=ARect.Right-ARect.Left;
Height:=ARect.Bottom-ARect.Top;
Canvas.Pen.Color:=clWhite;
Canvas.Brush.Color:=clWhite;
Canvas.Rectangle(0,0,Width,Height);
end; r1:=GetRValue(ColorFrom);
g1:=GetGValue(ColorFrom);
b1:=GetBValue(ColorFrom);
r2:=GetRValue(ColorTo);
g2:=GetGValue(ColorTo);
b2:=GetBValue(ColorTo); case ArtRectMode of
armHorizontal:
begin
dr:=(r2-r1)/Bmp.Width;
dg:=(g2-g1)/Bmp.Width;
db:=(b2-b1)/Bmp.Width;
nr:=r1;
ng:=g1;
nb:=b1;
with Bmp.Canvas do
begin
for i:=0 to Bmp.Width do
begin
r:=Trunc(nr);
g:=Trunc(ng);
b:=Trunc(nb);
// r:=Trunc(r1+(r2-r1)/Bmp.Width*i);
// g:=Trunc(g1+(g2-g1)/Bmp.Width*i);
// b:=Trunc(b1+(b2-b1)/Bmp.Width*i);
Pen.Color:=RGB(r,g,b);
MoveTo(i,0);
LineTo(i,Bmp.Height);
nr:=nr+dr;
ng:=ng+dg;
nb:=nb+db;
end;
end;
end;
armVertical:
begin
dr:=(r2-r1)/Bmp.Height;
dg:=(g2-g1)/Bmp.Height;
db:=(b2-b1)/Bmp.Height;
nr:=r1;
ng:=g1;
nb:=b1;
with Bmp.Canvas do
begin
for i:=0 to Bmp.Height do
begin
r:=Trunc(nr);
g:=Trunc(ng);
b:=Trunc(nb);
Pen.Color:=RGB(r,g,b);
MoveTo(0,i);
LineTo(Bmp.Width,i);
nr:=nr+dr;
ng:=ng+dg;
nb:=nb+db;
end;
end;
end;
armRectangle:
begin
YXScale:=Abs(Supplement/100);
n:=Trunc(Max(Bmp.Height/YXScale,Bmp.Width)/2);
dr:=(r2-r1)/n;
dg:=(g2-g1)/n;
db:=(b2-b1)/n;
nr:=r1;
ng:=g1;
nb:=b1;
with Bmp.Canvas do
begin
Brush.Style:=bsSolid;
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
for i:=n downto 0 do
begin
r:=Trunc(nr);
g:=Trunc(ng);
b:=Trunc(nb);
Pen.Color:=RGB(r,g,b);
// Brush.Color:=Pen.Color;
Brush.Style:=bsClear;
Rectangle(Bmp.Width div 2 -i,Bmp.Height div 2-Trunc(i*YXScale),
Bmp.Width div 2 +i,Bmp.Height div 2 +Trunc(i*YXScale));
nr:=nr+dr;
ng:=ng+dg;
nb:=nb+db;
end;
end;
end;
end;//case
ACanvas.CopyMode:=cmSrcCopy;
ACanvas.CopyRect(ARect,Bmp.Canvas,Rect(0,0,Bmp.Width,Bmp.Height));
Bmp.Free;
end;
procedure ExtractCaption(ACaption:string;var s1,s2,s3:string);
// s2 is the text of a Hot Key
var
i:Integer;
s:string;
blnFound:Boolean;
begin
s:=ACaption;
s1:='';
s2:='';
s3:='';
blnFound:=False;
while s<>'' do
begin
i:=Pos('&',s);
if i>0 then
begin
blnFound:=True;
s1:=s1+Copy(s,1,i-1);
s:=Copy(s,i+1,Length(s));
if s<>'' then
if s[1]='&' then
begin
s1:=s1+'&';
s:=Copy(s,2,Length(s));
blnFound:=False;
end;
end
else
begin
if blnFound then
begin
s2:=s[1];
s3:=Copy(s,2,Length(s));
end
else
s3:=s;
s:='';
end;
end;
end;
procedure DrawCaption(ACanvas:TCanvas;X,Y:Integer;ACaption:string);
var
s1,s2,s3:string;
OldPen:TPen;
OldBrush:TBrush;
OldFont:TFont;
begin
OldPen:=TPen.Create;
OldBrush:=TBrush.Create;
OldFont:=TFont.Create;
ExtractCaption(ACaption,s1,s2,s3);
with ACanvas do
begin
OldPen.Assign(Pen);
OldBrush.Assign(Brush);
OldFont.Assign(Font);
Pen.Mode:=pmMerge;
Brush.Style:=bsClear;
TextOut(X,Y,s1);
Font.Style:=Font.Style+[fsUnderline];
TextOut(PenPos.X,PenPos.Y,s2);
Font.Assign(OldFont);
TextOut(PenPos.X,PenPos.Y,s3); Pen.Assign(OldPen);
Brush.Assign(OldBrush);
end;
OldPen.Free;
OldBrush.Free;
OldFont.Free;
end;
procedure DrawArtText(ACanvas:TCanvas;X,Y:Integer;ColorFrom,ColorTo:TColor;
Text:string);
var
SrcBmp,BackBmp:TBitmap;
h,w:Integer;
SrcRect:TRect;
begin
SrcBmp:=TBitmap.Create;
BackBmp:=TBitmap.Create;
h:=ACanvas.TextHeight(Text);
w:=ACanvas.TextWidth(Text);
with SrcRect do
begin
Left:=0;
Top:=0;
Right:=w;
Bottom:=h;
end;
with SrcBmp do
begin
Width:=w;
Height:=h;
end;
with BackBmp do
begin
Width:=w;
Height:=h;
DrawArtRect(Canvas,SrcRect,ColorFrom,ColorTo,armVertical);
end;
with SrcBmp.Canvas do
begin
Font.Assign(ACanvas.Font);
Font.Color:=clWhite;
Brush.Color:=clBlack;
Pen.Color:=Brush.Color;
Rectangle(SrcRect);
DrawCaption(SrcBmp.Canvas,0,0,Text); // Mask background
ACanvas.CopyMode:=cmSrcInvert;
ACanvas.CopyRect(Rect(x,y,x+w,y+h),SrcBmp.Canvas,SrcRect); // Obtain the art text foreground
CopyMode:=cmSrcAnd;
CopyRect(SrcRect,BackBmp.Canvas,SrcRect);
end;
with ACanvas do
begin
// Merge foreground and background
CopyMode:=cmSrcPaint;
COpyRect(Rect(x,y,x+w,y+h),SrcBmp.Canvas,SrcRect);
end;
SrcBmp.Free;
BackBmp.Free;
end;
ARect: TRect; Selected: Boolean);
var
MenuItem:TMenuItem;
MenuFullRect,MenuItemRect,SrcRect,SelectRect,DestRect:TRect;
SrcBmp:TBitMap;
BlankWidth,LabelWidth,w:Integer;
LabelString:string;
begin
MenuItem:=TMenuItem(Sender);
DestRect:=ARect;
with SrcRect do
begin
Left:=0;
Top:=0;
Right:=ARect.Right-ARect.Left;
Bottom:=ARect.Bottom-ARect.Top;
if MenuItem.MenuIndex=MenuItem.Parent.Count-1 then
begin
Right:=Right+ClientWidth-ARect.Right+MenuOffset;
DestRect.Right:=DestRect.Left+Right-Left;
end;
end;
SelectRect:=SrcRect;
SelectRect.Right:=SelectRect.Left+ARect.Right-ARect.Left;
with MenuFullRect do
begin
Left:=0;
Top:=0;
Right:=ClientWidth;
Bottom:=ARect.Bottom-ARect.Top;
end;
with MenuItemRect do
begin
Left:=DestRect.Left-MenuOffset;
Top:=0;
Right:=Left+DestRect.Right-DestRect.Left;
Bottom:=DestRect.Bottom-DestRect.Top;
end;
SrcBmp:=TBitmap.Create;
with SrcBmp do
begin
Width:=SrcRect.Right-SrcRect.Left;
Height:=SrcRect.Bottom-SrcRect.Top;
end;
if blnMenuRefresh then
begin
with MenuBackground do
begin
Width:=MenuFullRect.Right;
Height:=MenuFullRect.Bottom;
DrawArtRect(Canvas,MenuFullRect,clSkyBlue,clYellow,armHorizontal);
end;
blnMenuRefresh:=False;
end;
with SrcBmp.Canvas do
begin
CopyMode:=cmSrcCopy;
CopyRect(SrcRect,MenuBackground.Canvas,MenuItemRect); if MenuItem.MenuIndex=MenuItem.Parent.Count-1 then
begin
Font.Size:=10;
Font.Name:='ËÎÌå';
Font.Charset:=GB2312_Charset;
LabelString:='';
LabelWidth:=0;
BlankWidth:=SrcRect.Right-SrcRect.Left-SelectRect.Right+SelectRect.Left;
w:=TextWidth(Flower);
if BlankWidth>w+70 then
begin
LabelWidth:=w;
LabelString:=Flower;
end;
w:=TextWidth(FlowerSoft);
if BlankWidth>w+70 then
begin
LabelWidth:=w;
LabelString:=FlowerSoft;
end;
w:=TextWidth(FlowerSoftware);
if BlankWidth>w+70 then
begin
LabelWidth:=w;
LabelString:=FlowerSoftware;
end;
w:=TextWidth(FlowerSoftwareStudio);
if BlankWidth>w+70 then
begin
LabelWidth:=w;
LabelString:=FlowerSoftwareStudio;
end;
if LabelString<>'' then
DrawArtText(SrcBmp.Canvas,SrcRect.Right-LabelWidth-70,0,clRed,clLime,
LabelString);
end;
Font.Size:=9;
Font.Name:='ËÎÌå';
Font.Charset:=GB2312_Charset;
Brush.Style:=bsClear;
Pen.Style:=psSolid;
Pen.Mode:=pmCopy; if MenuItem.Enabled then
begin
if Selected then
begin
Pen.Color:=clRed;
Rectangle(SelectRect);
Font.Color:=clRed;
DrawCaption(SrcBmp.Canvas,SrcRect.Left+8,SrcRect.Top+6,MenuItem.Caption);
end
else
begin
Font.Color:=clRed;
DrawCaption(SrcBmp.Canvas,SrcRect.Left+5,SrcRect.Top+4,MenuItem.Caption);
end;
end
else
begin
Font.Color:=clGray;
DrawCaption(SrcBmp.Canvas,SrcRect.Left+5,SrcRect.Top+4,MenuItem.Caption);
end;
end;
ACanvas.CopyMode:=cmSrcCopy;
ACanvas.CopyRect(DestRect,SrcBmp.Canvas,SrcRect);
SrcBmp.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MenuBackground:=TBitmap.Create;
MenuOffset:=ClientOrigin.X-Left;
blnMenuRefresh:=True;end;procedure TForm1.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
blnMenuRefresh:=True;end;procedure TForm1.FormDestroy(Sender: TObject);
begin
MenuBackground.Free;
end;end.