Q: 怎么来改变ListBox的字体呢?就修改其中的一行。

A: 先把ListBox1.Style 设成lbOwnerDrawFixed 
然后在 OnDrawItem 事件下写下如下代码

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; 
Rect: TRect; State: TOwnerDrawState); 
var 
Offset: Integer; 
begin 
Offset := 2; 
with (Control as TListBox).Canvas do begin 
FillRect(Rect); 
if Index = 2 then begin 
Font.Name := 'Fixedsys'; 
Font.Color := clRed; 
Font.Size := 12; 
end else begin 
Font.Name := 'Arial'; 
Font.Color := clBlack; 
Font.Size := 8; 
end; 
if odSelected in State then begin 
Font.Color := clWhite; 
end; 
TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index]); 
end; 
end; 
---------------------------------------- 
Q:怎么在RichEdit里面插入图片?

A: 请到这里来看看会找到答案

http://www.undu.com/Articles/991107c.html
---------------------------------------------- 
Q:怎么才能目录呢?

A:我来。

uses ShellAPI;

procedure DeleteFiles(Source: string); 
var 
FO: TShFileOpStruct; 
begin 
FillChar(FO,SizeOf(FO),#0); 
FO.Wnd := Form1.Handle; 
FO.wFunc := FO_Delete; 
FO.pFrom := PChar(Source); 
ShFileOperation(FO); 
end;

procedure EmptyDirectory(Path: String); 
begin 
if DirectoryExists(Path) then 
begin 
DeleteFiles(Path+'*'); 
end 
else 
ForceDirectories(Path); 
end; 
-------------------------------------------------- 
Q:如何映射网络驱动器?

比如我要把Serversys映射为F盘。我需要一个函数比如

给出输入参数为serversyshomebruno给我的返回值是F:homebruno

A:

Function UNCToDrive(UNCPath: STring): STring; 
var 
DriveNum: Integer; 
DriveChar: Char; 
DriveBits: set of 0..25; 
StartSTr,TestStr: STring; 
begin 
result := UNCPath; 
StartSTr := UNCPath; 
Integer(DriveBits) := GetLogicalDrives; 
for DriveNum := 0 to 25 do 
begin 
if (DriveNum in DriveBits) then begin 
DriveChar := Char(DriveNum + ord('A')); 
TestSTr := ExpandUNCFileName(DriveChar+':'); 
If TEstStr <> '' then 
If Pos(Uppercase(TestSTr),Uppercase(STartSTr)) > 0 then 
begin 
Delete(StartSTr,1,Length(TestSTr)); 
result := DriveChar+':'+StartSTr; 
break; 
end; 
end; 
end; 
end; 
--------------------------------------------------------- 
Q:我有一些特殊语言的字体来用,它们存储在我的EXE文件里,但是两点。

* 我不想放到font文件夹里 
* 我不想从EXE文件里面提取出来

如果可能,请告诉我。

因为,我的字体是自己做的不是windows自带的,我想保护自己的东西。

A:不太可能,必须提取出来。你可以使用这个保护过程来保护你的文件不被修改和删除。

在EXE执行的时候把字体放到临时文件夹里,结束的时候删除它。

function ProtectFile(sFilename : string) : hFile; 
var 
hf: hFile; 
lwHFileSize, lwFilesize: longword; 
ofs : TOFStruct; 
begin 
if FileExists(sFilename) then 
begin 
hf := OpenFile(pchar(sFilename), ofs, OF_READ or OF_WRITE or OF_SHARE_EXCLUSIVE); 
if hf <> 0 then 
begin 
lwFilesize := GetFileSize(hf, @lwHFileSize); 
if LockFile(hf, 0, 0, lwFilesize, lwHFilesize) then 
Result := hf else Result := 0; 
end 
else Result := 0; 
end 
else Result := 0; 
end;

//.. 
var 
ResS: TResourceStream; 
TempPath: array [0..MAX_PATH] of Char; 
TempDir: string; 
begin 
GetTempPath(Sizeof(TempPath), TempPath); 
TempDir := StrPas(Path); 
ResS := TResourceStream.Create(hInstance, 'SOME_FONT', 'RT_FONT'); 
ResS.SavetoFile(TempDir+'some_font.ttf'); 
ResS.Free; 
AddFontResource(TempDir+'some_font.ttf'); 
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0); 
ProtectFile(TempDir+'some_font.ttf'); 
end; 
------------------------------------------------------- 
Q:如何得到当前的ProgramFiles得路径?

A:用读写注册表的方法就可以做到。

代码如下:

uses registry;

procedure TForm1.Button1Click(Sender: TObject); 
var 
reg:TRegistry; 
begin 
reg:=TRegistry.Create; 
reg.RootKey:=HKEY_LOCAL_MACHINE; 
if reg.OpenKey('SOFTWAREMicrosoftWindowsCurrentVersion',false) then 
begin 
edit1.Text:=reg.ReadString('ProgramFilesDir'); 
reg.CloseKey; 
reg.Free; 
end; 
end; 
-------------------------------------------------------------- 
Q:如何在Jpg图像上写上字?

A:这里有个代码。

hmm, here's a sample with help of Bitmap, you can chance the brush style of canvas to bsClear to make the text transparent

uses 
Jpeg;

procedure TForm1.Button1Click(Sender: TObject); 
var 
Bmp : TBitmap; 
Jpg : TJpegImage; 
begin 
try 
Bmp := TBitmap.Create; 
Jpg := TjpegImage.Create; 
Jpg.LoadFromFile('c:img.jpg'); 
Bmp.Assign(Jpg); 
Bmp.Canvas.Brush.Style := bsClear; 
Bmp.Canvas.Font.Color := clYellow; 
Bmp.Canvas.TextOut(10,10,'Hello World'); 
Jpg.Assign(Bmp); 
Jpg.SaveToFile('c:img2.jpg'); 
finally 
bmp.Free; 
jpg.Free; 
end; 
end; 
---------------------------------------------------- 
DBGrid中如何让回车变为光标右移动 :

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; 
Shift: TShiftState); 
begin 
if key=VK_F1 then 
begin 
DBGrid1.DataSource:=DataSource1; 
ADOTable1.Active:=true; 
ADOTable2.Active:=false; 
end 
else if key=VK_F2 then 
begin 
DBGrid1.DataSource:=DataSource2; 
ADOTable2.Active:=true; 
ADOTable1.Active:=false; 
end 
end ;

case key of 
vk_f11: 
begin

end;

if edit1.Text=ADOTable1.FieldByName('no').AsString then 
begin 
edit2.Text:=ADOTable1.FieldValues['pname']; 
edit3.Text:=ADOTable1.FieldValues['kroom']; 
edit4.Text:=ADOTable1.FieldValues['dname']; 
end

DBGrid中如何让回车变为光标右移动 
在Form.OnKeyPress事件中写如下代码:

if Key = #13 then 
if ActiveControl = DBGrid1 then begin 
TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1; 
Key := #0; 
end;

有2点需要注意: 
1.当光标达到DBGird最右列的时候,再按回车,光标还会停留在原地。 
2.Key := #0一句让光标移动到下一列以后处于浏览状态,如果去掉这行代码光标移动到下一列以后将处于编辑状态。 
----------------------------------------------------------------- 
Q:怎么用delphi修改文件的时间呢?

在windows下,属性里面有三个日起,创建,修改,存储。我怎么来修改啊?

A:Here is the excerpt from the Jedi Code Library. If it is not complete then get the JCL.

type 
// indicates the file time to set, used by SetFileTimesHelper and SetDirTimesHelper 
TFileTimes = (ftLastAccess, ftLastWrite, ftCreation);

function SetFileTim
esHelper(const FileName: string; const DateTime: TDateTime; Times: TFileTimes): Boolean; 
var 
Handle: THandle; 
FileTime: TFileTime; 
SystemTime: TSystemTime; 
begin 
Result := False; 
Handle := CreateFile(PChar(FileName), GENERIC_WRITE, FILE_SHARE_READ, nil, 
OPEN_EXISTING, 0, 0); 
if Handle <> INVALID_HANDLE_VALUE then 
try 
//SysUtils.DateTimeToSystemTime(DateTimeToLocalDateTime(DateTime), SystemTime); 
SysUtils.DateTimeToSystemTime(DateTime, SystemTime); 
if Windows.SystemTimeToFileTime(SystemTime, FileTime) then 
begin 
case Times of 
ftLastAccess: 
Result := SetFileTime(Handle, nil, @FileTime, nil); 
ftLastWrite: 
Result := SetFileTime(Handle, nil, nil, @FileTime); 
ftCreation: 
Result := SetFileTime(Handle, @FileTime, nil, nil); 
end; 
end; 
finally 
CloseHandle(Handle); 
end; 
end;

//--------------------------------------------------------------------------------------------------

function SetFileLastAccess(const FileName: string; const DateTime: TDateTime): Boolean; 
begin 
Result := SetFileTimesHelper(FileName, DateTime, ftLastAccess); 
end;

//--------------------------------------------------------------------------------------------------

function SetFileLastWrite(const FileName: string; const DateTime: TDateTime): Boolean; 
begin 
Result := SetFileTimesHelper(FileName, DateTime, ftLastWrite); 
end;

//--------------------------------------------------------------------------------------------------

function SetFileCreation(const FileName: string; const DateTime: TDateTime): Boolean; 
begin 
Result := SetFileTimesHelper(FileName, DateTime, ftCreation); 
end; 
----------------------------------------------------------------------

Delphi经验总结(2)的更多相关文章

  1. Delphi经验总结(1)

    先人的DELPHI基础开发技巧 ◇[DELPHI]网络邻居复制文件 uses shellapi; copyfile(pchar('newfile.txt'),pchar('//computername ...

  2. Delphi经验总结(3)

    ------------------------------------------------------- ◇删掉程序自己的exe文件 procedure TForm1.FormClose(Sen ...

  3. JNI 翻译 转 Delphi 的 经验 方法

    首发在 ①FireMonkey[移动开发] 16523232 欢迎使用 FMX 开发手机程序的高手来访. 注意:如果您看了本文,翻译了 JNI,请发布到本群共享一份.不同意本规定的,请立即删除本文.凡 ...

  4. Delphi调用WebService(通过SoapHeader认证)经验总结

    项目(Delphi开发)需要调用另一个系统的WebService.走了不少弯路,现记录总结一下经验.以下是WebService要求: 1.WebService概述 营销Webservice接口采用Ap ...

  5. delphi 升级到xe7后的一些个人经验

    http://blog.csdn.net/span12/article/details/42522091 你只要记住 字符串使用变了.VCL 下面所有的 char 改 ansichar string ...

  6. Delphi编程防止界面卡死的方法经验分享

    Delphi编程防止界面卡死的方法经验分享! 1.循环里面防止界面卡死的方法可以使用Application.ProcessMessages:  例如下列方法:    var      n: Integ ...

  7. Delphi 10.1.2 berlin开发跨平台APP的几点经验

    1.ios不允许app有退出功能,所以不能调用Application.Terminate. 2.info.plist文件的自定义:info.plist文件是由info.plist.TemplateiO ...

  8. (转: daifubing的博客 )Delphi二维码中文支持、分组、批量打印经验小结

    一直也没接触到什么复杂的报表,都是一些简单的报表,在DelphI下使用QuickReport一般也就能满足需要了,由于公司现在需求的变化,对条码扫描提出了新的要求,主要是扫码要包含更多地内容,以前的一 ...

  9. Delphi面向对象设计的经验原则(61条)

    (1)所有数据都应该隐藏在所在的类的内部. (2)类的使用者必须依赖类的共有接口,但类不能依赖它的使用者. (3)尽量减少类的协议中的消息. (4)实现所有类都理解的最基本公有接口[例如,拷贝操作(深 ...

随机推荐

  1. Java基础-常量,变量,成员变量,局部变量

    在java中,数据是以常量和变量两种方法形式进行存储和表示的(实际上,所有程序的数据都是这两种形式). 变量 变量代表程序的状态.程序通过改变变量的值来改变整个程序的状态,或者说得更大一些,也就是实现 ...

  2. 基于spring mvc的注解DEMO完整例子

    弃用了struts,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件.本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mv ...

  3. C语言+SDL2 图形化编程

    程设大作业小火车第一版本是命令行界面,第二版本是图形化界面,由于egg库对以后工程开发没有用,我不想用egg库,花了很长时间浏览了一下OpenGL的中文教程,觉得好复杂,需要看很多很多才能写出个简单的 ...

  4. 【Matplotlib】 增加图例

    相关文档: Legend guide legend() command Legend API 控制图例入口 无参调用 legend() 会自动获取图例 handles 以及相关的 labels.其对应 ...

  5. 【poj2079】 Triangle

    http://poj.org/problem?id=2079 (题目链接) 题意 求凸包内最大三角形面积 Solution 旋转卡壳. 只会n²的做法,但是竟然过了.就是枚举每一个点,然后旋转卡壳另外 ...

  6. tp三大自动

    ThinkPHP三大自动 (2012-03-21 10:48:56) 转载▼ 标签: thinkphp 三大自动 自动验证 自动完成 自动填充 自动映射 字段映射 杂谈 分类: php 一.自动验证 ...

  7. javaweb学习总结(三十一)——国际化(i18n)

    一.国际化开发概述 软件的国际化:软件开发时,要使它能同时应对世界不同地区和国家的访问,并针对不同地区和国家的访问,提供相应的.符合来访者阅读习惯的页面或数据. 国际化(internationaliz ...

  8. css3应用之自定义选中文字的背景颜色

    在看很多的博客主题时候发现大多数都对选中文字的背景颜色做了相应的处理.其实这样是很符合用户体验的.因为有很多的人会用鼠标选择着一行一行的阅读.其中就包括本人... 浏览器中默认的选中的文字颜色为白色, ...

  9. WebSocket 基本函数

    1.构造函数   WebSocket(char *host); 创建一个websocket对象,接受一个参数以ws://靠头,就像发起一个HTTP请求一样用http://开头 var ws=new W ...

  10. html空格小结

      按下space键产生的空格.在HTML中,如果你用空格键产生此空格,空格是不会累加的(只算1个).要使用html实体表示才可累加,该空格占据宽度受字体影响明显而强烈.   它叫“半角空格”, 透明 ...