1. 今天用RegisterClass的时候发现windows和classes单元都有,而DELPHI引用单元的顺序是从右到左的,所以
uses Windows,Classes,Common,BaseThread,SysUtils,abs....这样就是引用到Classes的方法
2. C#引用DELPHI作的DLL的例子
QSystem.LogFile.dll
library QSystem.LogFile;
uses
SysUtils,
Classes;
{$R *.res}
function Log(fname,msg:PChar):integer;stdcall;
begin
end;
exports
Log;
end.
Code
[DllImport("QSystem.LogFile.dll",CharSet=CharSet.Ansi)]
public static extern int Log(String fname, String msg);
private void button1_Click(object sender, EventArgs e)
{
String temp1 = "test1";
String temp2 = "test2";
Log(temp1, temp2);
}
这里DLL写的时候,要注意大小写,CharSet 要注意如果改成AUTO,传入的参数有可能只有一个字符,嘿嘿
3. 读取SINGLE的字节
Code
procedure TForm1.Button1Click(Sender: TObject);
var temp1,temp2:single;
data : array[1..4] of byte;
P1,p2 : POINTER;
temp:string;
len:integer;
begin
fillchar(data,4,0);
temp1 := -112.25;
temp2 := 1111;
len := sizeof(temp1);
p1 := @TEMP1;
new(p2);
move(p1,data,len);
move(data,p2,len);
temp2 := single(p2^);
temp:= floattostr(temp2);
showmessage(temp);
end;
考虑是不是应该是DLEPHI内嵌的汇编?。。。。有更好的方法的请留言
4. 获取ORACLE存储过程或者FUNCTION的参数表:
param
storedproc1.StoredProcName := edit1.text;
storedproc1.Prepare;
for i:=0 to storedproc1.ParamCount -1 do begin
temp := storedproc1.Params[i].Name;
if StoredProc1.Params[i].ParamType = ptInputOutput then
temp := temp + '| ParamType:ptInputOutput |' ;
if StoredProc1.Params[i].ParamType = ptUnknown then
temp := temp + '| ParamType:ptUnknown |' ;
if StoredProc1.Params[i].ParamType = ptInput then
temp := temp + '| ParamType:ptInput |' ;
if StoredProc1.Params[i].ParamType = ptOutput then
temp := temp + '| ParamType:ptOutput |' ;
if StoredProc1.Params[i].ParamType = ptResult then
temp := temp + '| ParamType:ptOutput |' ;
if storedproc1.Params[i].DataType = ftInteger then
temp := temp + '| TYPE:Integer |'
else
temp := temp + '| TYPE:String |';
showmessage(temp);
end;
注意:
1). 参数里面不能有Boolean类型,否则Delphi就会所有参数都不能解析出来
2).char和Varchar2类型参数类型都是ftString,而integer和number都是ftFloat,date就是ftDateTime
3).FUNCTION的话会自动有一个"Result"的参数
4).参数类型是NUMBER的整型,可以用asstring传入字符型的数值
5).存储过程Unprepare后,没有将参数清空,必须用param.Clear,否则下次获取的时候会出现类型错误
5. listview加背景
listview
procedure TFrmmain.lvstationCustomDraw(Sender: TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
var
Bitmap : TBitMap;
begin
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('.\back.bmp');
lvstation.Canvas.Draw(0,0,Bitmap);
// lvstation.Color:=clwhite;
SetBkMode(Canvas.Handle,TRANSPARENT);
// Perform(LVM_SETTEXTBKCOLOR,0,LongInt(CLR_NONE)); //add commctrl
// ListView_SetBKColor(Handle,CLR_NONE);
end;
6.给scrollbox加背景
ScrollBox1
procedure TForm1.Button1Click(Sender: TObject);
var
c:TCanvas;
bit:TBitmap;
begin
c:=TControlCanvas.Create;
bit:=TBitmap.Create;
try
// c:=TCanvas.Create; 可以这样给PANEL加背景
// c.Handle:=getdc( Panel1.Handle);
TControlCanvas(c).Control:=ScrollBox1;
c.Brush.Style:=bsClear;
//c.Pen.Color:=clBlue;
//c.Rectangle(5,5,15,15);
bit.LoadFromFile('F:\enli\WDA\Bin\back.bmp');
c.StretchDraw(rect(0,0,ScrollBox1.Width,ScrollBox1.Height),bit);
finally
c.Free;
bit.Free;
end;
end;