托盘程序中这个函数怎么老是报错 [Error] Unit1.pas(32): Unknown directive: 'message',请大家出手相助 (50分

  • 主题发起人 主题发起人 jiafei528
  • 开始时间 开始时间
J

jiafei528

Unregistered / Unconfirmed
GUEST, unregistred user!
托盘程序中这个函数怎么老是报错 [Error] Unit1.pas(32): Unknown directive: 'message',请大家出手相助 (50分)<br />procedure WMNID(var msg:TMessage); message WM_NID;
begin
case msg.LParam of
WM_LBUTTONUp; Form1.Visible:=not Form1.Visible;
WM_RBUTTONUP: ShowMessage(&amp;iexcl;&amp;reg;&amp;Auml;ú&amp;micro;&amp;atilde;&amp;raquo;÷&amp;micro;&amp;Auml;&amp;Ecirc;&amp;Ccedil;&amp;Oacute;&amp;Ograve;&amp;frac14;ü&amp;iexcl;&amp;macr;);
End;
End;
 
请参考archonwang的笔记:

有关双击dbgrid排序的问题(想让用户双击dbgird控件的某一个字段时就升序,再双击就降序....?)【DFW:DouZheng】
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
temp, title: string;
begin
temp := Column.FieldName;
qusp.Close;
if Column.Index <> lastcolumn then
begin
if (Pos('↑', DBGrid1.Columns[LastColumn].Title.Caption) > 0) or (Pos('↓', DBGrid1.Columns[LastColumn].Title.Caption) > 0) then
DBGrid1.Columns[LastColumn].Title.Caption := Copy(DBGrid1.Columns[LastColumn].Title.Caption, 3, Length(DBGrid1.Columns[LastColumn].Title.Caption) - 2);
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[Column.Index].Title.Caption := '↑' + DBGrid1.Columns[Column.Index].Title.Caption;
lastcolumn := column.Index;
end
else
begin
LastColumn := Column.Index;
title := DBGrid1.Columns[LastColumn].Title.Caption;
if Pos('↑', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' desc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↓' + title;
end
else if Pos('↓', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end
else
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end;
end;
qusp.Open;
end;

这里有详细:
http://delphibbs.com/keylife/iblog_show.asp?xid=4091
 
我不明白你的意思,
能不能说清楚点?
 
是不是 得到 DBGrid1.Columns[1].Index ?
单击时不要得到?什么意思?
 
如何双击DBGRID的TITL时得到其INDEX,而不是单击时,如何?
并且实现只能移动各列的宽度,而不能移动各列的顺序?请大师再次出手相助
 
没有这样的双击事件,自己定义一个变量在Click中控制吧
 
我的想法是,加一个Timer控件,在第一次OnTitleClick做个标志,说明已经Click,并记录Click的Title,启动Timer.在OnTimer中判断是否在规定时间第二次Click,否则清除标志,停止Timer
 
1. 如何固定DBGRID各列的顺序,而不能移动各列的顺序?但可移动各列的宽度,请大师再次出手相助!


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;
type
myGrid= class( TCustomGrid);

type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
procedure DBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;

begin
for i:= 1 to 10 do
ADODataSet1.FieldDefs.Add('A'+inttostr(i),ftstring,6);
ADODataSet1.CreateDataSet;
ADODataSet1.Open;

for i:= 1 to 10 do
ADODataSet1.AppendRecord(['1','2','3','4','5','6','7','8','9','10']);
ADODataSet1.First;


end;

procedure TForm1.DBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if gsColMoving = myGrid(DBGrid1).FGridState then
begin /////我爱啃猪脚!!!!!!!!!!!!!!!!!!!!!!!!
myGrid(DBGrid1).FGridState := gsNormal;
DBGrid1.Repaint;
end;
end;

end.


object Form1: TForm1
Left = 192
Top = 103
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 88
Width = 536
Height = 260
Align = alBottom
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
OnMouseDown = DBGrid1MouseDown
end
object ADODataSet1: TADODataSet
Parameters = <>
Left = 136
Top = 48
end
object DataSource1: TDataSource
DataSet = ADODataSet1
Left = 192
Top = 40
end
end
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;
const
My_Msg_Refresh = wm_user + 1001;
type
myGrid = class(TCustomGrid);

type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
procedure DBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DBGrid1DblClick(Sender: TObject);
procedure DBGrid1TitleClick(Column: TColumn);

private
Fstr: string;

public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 1 to 10 do
ADODataSet1.FieldDefs.Add('A' + inttostr(i), ftstring, 6);
ADODataSet1.CreateDataSet;
ADODataSet1.Open;
for i := 1 to 10 do
ADODataSet1.AppendRecord(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']);
ADODataSet1.First;
end;

procedure TForm1.DBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if gsColMoving = myGrid(DBGrid1).FGridState then
begin
myGrid(DBGrid1).FGridState := gsNormal;
DBGrid1.Repaint;
end;

end;

procedure TForm1.DBGrid1DblClick(Sender: TObject);
var
Pt: TPoint;
g: TGridCoord;
begin
GetCursorPos(Pt);
pt := DBGrid1.ScreenToClient(pt);
g := DBGrid1.MouseCoord(pt.X, pt.y);
if g.y = 0 then
Fstr := '双击';

end;

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
str: string;
i, j: integer;
begin

for i := 0 to DBGrid1.Columns.Count - 1 do
begin
str := DBGrid1.Columns.Items.Title.Caption;
j := pos(' ', str);
DBGrid1.Columns.Items.Title.Caption := copy(str, 1, j - 1);

end;
if Fstr = '' then
Column.Title.Caption := Column.Title.Caption + ' ' + '单击'
else
Column.Title.Caption := Column.Title.Caption + ' ' + Fstr;
Fstr := '';
end;

end.
 

http://www.efile.com.cn/efile/dfw@97546/dbgrid.zip

源码 + exe
 
非常感谢hfghfghfg的解疑,分肯定会发的,这里再问多点的是:如何确认区分是左,右键呢,还有就是在DBGRID的非TITLE区无法接受到双,单击事件呢?
 
MouseDown事件中判断 button=mbright or mbleft
 
多人接受答案了。
 
后退
顶部