现象:
TColorBox::Style属性加上cbCustomColor,运行后选择Custom...跳出颜色对话框~~
选择自定义颜色中未定义的一组,将抛出异常(Delphi6、Delphi7都有)~~function TCustomColorBox.PickCustomColor: Boolean;
var
LColor: TColor;
begin
with TColorDialog.Create(nil) do
try
LColor := ColorToRGB(TColor(Items.Objects[0]));
Color := LColor;
CustomColors.Text := Format('ColorA=%.8x', [LColor]);
Result := Execute;
if Result then
begin
Items.Objects[0] := TObject(Color); //Color值为-1
Self.Invalidate;
end;
finally
Free;
end;
end;原因:
function TCustomComboBoxStrings.GetObject(Index: Integer): TObject;
begin
Result := TObject(SendMessage(ComboBox.Handle, CB_GETITEMDATA, Index, 0));
if Longint(Result) = CB_ERR then //ComboBox获取Item的Data时-1正好是错误标识CB_ERR~
Error(SListIndexError, Index);
end;
TColorBox::Style属性加上cbCustomColor,运行后选择Custom...跳出颜色对话框~~
选择自定义颜色中未定义的一组,将抛出异常(Delphi6、Delphi7都有)~~function TCustomColorBox.PickCustomColor: Boolean;
var
LColor: TColor;
begin
with TColorDialog.Create(nil) do
try
LColor := ColorToRGB(TColor(Items.Objects[0]));
Color := LColor;
CustomColors.Text := Format('ColorA=%.8x', [LColor]);
Result := Execute;
if Result then
begin
Items.Objects[0] := TObject(Color); //Color值为-1
Self.Invalidate;
end;
finally
Free;
end;
end;原因:
function TCustomComboBoxStrings.GetObject(Index: Integer): TObject;
begin
Result := TObject(SendMessage(ComboBox.Handle, CB_GETITEMDATA, Index, 0));
if Longint(Result) = CB_ERR then //ComboBox获取Item的Data时-1正好是错误标识CB_ERR~
Error(SListIndexError, Index);
end;
解决方案 »
- 请问怎么拦截错误提示!
- 请问数据库脚本,怎么通过写程序自动在SQLSEVER生成数据库
- sleep函数的最小延时时间竟然为10ms?
- 请问这个IP是哪里的? 219.130.108.117
- ===============又来广告了,想拿分的up=========
- 我在主程序里面想包含进一个文件,怎么做
- 如何禁用/启用本地连接??
- 哪位高手可以告诉我如何用Delphi调用VC或者C++Builder编译的dll文件
- 哈哈,,,北京多少人!肯定比他们多多了!:)
- 关于ServerSocket, ClientSocket的问题
- 请教DatasetProvider
- 如何用BitBlt函数实现贴图时将源图像的背景色滤除?
interface
uses
Windows, Controls, Forms,ComCtrls,Classes,StdCtrls;
type
Tfrm_main = class(TForm)
btn_backup: TButton;
ProgressBar: TProgressBar;
procedure btn_backupClick(Sender: TObject);
private
public
end;
var
frm_main: Tfrm_main;
implementation
uses SQLDMO, ComObj;
{$R *.DFM}
type
TBackupSink = class(TInterfacedObject, BackupSink)
private
function PercentComplete(const Message: WideString; Percent: Integer): HResult; stdcall;
function NextMedia(const Message: WideString): HResult; stdcall;
function Complete(const Message: WideString): HResult; stdcall;
end;function TBackupSink.PercentComplete(const Message: WideString; Percent: Integer): HResult;
begin
frm_main.ProgressBar.Position := Percent;
Result := S_OK;
end;function TBackupSink.NextMedia(const Message: WideString): HResult;
begin
Result := S_OK;
end;function TBackupSink.Complete(const Message: WideString): HResult;
begin
Result := S_OK;
end;Procedure Tfrm_main.btn_backupClick(Sender: TObject);
var
FInterfaceConnection: Integer;
Backup : Variant;
SQL_SERVER : Variant;
begin
SQL_SERVER := CreateOLEObject('SQLDMO.SQLServer');
Backup := CreateOLEObject('SQLDMO.Backup');
Backup.Action := SQLDMOBackup_Database;
Backup.Database := 'test';
Backup.BackupSetName:= 'test'; SQL_SERVER.LoginSecure := False;
// SQL_SERVER.LoginSecure := True; // Win Auth.
SQL_SERVER.login := 'login';
SQL_SERVER.password := 'heslo';
Backup.Files := 'c:\test.bak'; SQL_SERVER.Connect('(local)'); InterfaceConnect(Backup, IID_BackupSink, TBackupSink.Create, FInterfaceConnection);
Backup.SQLBackup (SQL_SERVER);
InterfaceDisconnect(Backup, IID_BackupSink, FInterfaceConnection);
ProgressBar.Position := 0;
end;end.