?? syspublictmp.pas
字號(hào):
來自:meteor007, 時(shí)間:2004-8-23 10:17:04, ID:2774334
DATEPART
返回代表指定日期的指定日期部分的整數(shù)。
var:
stryourdate:string;
yourdate:TDateTime;
stryourdate:=FormatDateTime('yyyy/mm/dd',Yourdate);
stryourdate就是你想要的
還可得到年或月,日
語法
DATEPART ( datepart , date )
year(datetime)取年
month(datetime)取月
day(datetime)取天
}
{
SQL語句,縱列轉(zhuǎn)橫列
sTable.db
庫(kù)位 貨物編號(hào) 庫(kù)存數(shù)
1 0101 50
1 0102 60
1 0103 50
2 0101 90
2 0103 100
2 0111 30
3 0101 120
3 0102 110
4 0101 11
只列出表中庫(kù)位為1、2、3的數(shù)據(jù),格式如下:
貨物編號(hào) 庫(kù)位1 庫(kù)位2 庫(kù)位3
0101 50 90 120
0102 60 110
0103 50 100
0111 30
請(qǐng)問用一句sql語句怎么實(shí)現(xiàn)?
select a.貨物編號(hào),sum(b.庫(kù)存數(shù)),sum(c.庫(kù)存數(shù)),sum(d.庫(kù)存數(shù))
from stable a
left join (select 貨物編號(hào), 庫(kù)存數(shù) from stable where 庫(kù)位=1)b on a.貨物編號(hào)=b貨物編號(hào)
left join (select 貨物編號(hào), 庫(kù)存數(shù) from stable where 庫(kù)位=2)c on a.貨物編號(hào)=c。貨物編號(hào)
left join (select 貨物編號(hào), 庫(kù)存數(shù) from stable where 庫(kù)位=3)c on a.貨物編號(hào)=d。貨物編號(hào)
group by a.貨物編號(hào)
//※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※//
}
{
讓edit只輸入數(shù)字和小數(shù)點(diǎn)?
寫在onkeypress事件里面
if not (key in ['0'..'9',#8]) then
begin
if (key='.') and (pos('.',Tedit(sender).Text)=0) then exit;
key:=#0;
Messagebeep(0);
end;
在KeyPress里控制怎么都不完善!
如果Ctrl+C,Ctrl+V怎么辦?
如果右鍵拷貝、粘貼呢?
所以只有在OnChange事件中才能完善控制:
procedure TForm.EditChange(Sender: TObject);
begin
try
StrToFloat((Sender as TEdit).Text);
except
(Sender as TEdit).Text:=Copy((Sender as TEdit).Text,1,
Length((Sender as TEdit).Text)-1);
(Sender as TEdit).SelStart:=Length((Sender as TEdit).Text);
end;
end;
}
{
Format('x=%d', [12]); //'x=12' //最普通
Format('x=%3d', [12]); //'x= 12' //指定寬度
Format('x=%f', [12.0]); //'x=12.00' //浮點(diǎn)數(shù)
Format('x=%.3f', [12.0]); //'x=12.000' //指定小數(shù)
Format('x=%.*f', [5, 12.0]); //'x=12.00000' //動(dòng)態(tài)配置
Format('x=%.5d', [12]); //'x=00012' //前面補(bǔ)充0
Format('x=%.5x', [12]); //'x=0000C' //十六進(jìn)制
Format('x=%1:d%0:d', [12, 13]); //'x=1312' //使用索引
Format('x=%p', [nil]); //'x=00000000' //指針
Format('x=%1.1e', [12.0]); //'x=1.2E+001' //科學(xué)記數(shù)法
Format('x=%%', []); //'x=%' //得到"%"
S := Format('%s%d', [S, I]); //S := S + StrToInt(I); //連接字符串
}
{
一、Thread類的創(chuàng)建:
unit Thread;
// 線程類的創(chuàng)建
// 編譯環(huán)境: Windows 2003 Sever Delphi 7.0 Enterprise
interface
uses classes,sysutils,StdCtrls;
type
TB = class(TThread)
private
i :integer;
Fedt :TEdit;
procedure Update ;
public
procedure execute;override;
constructor create(IsSuspended :Boolean;edt :TEdit);
end;
implementation
uses MainForm;
procedure TB.Update;
begin
Fedt.Text :=inttostr(i);
end;
constructor TB.create(IsSuspended: Boolean; edt: TEdit);
begin
inherited create(IsSuspended);
Fedt := edt;
end;
procedure TB.execute;
begin
i:=0;
while(not Terminated) do
begin
Synchronize(Update);
inc(i);
end;
end;
end.
二、Thread類的使用:
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Thread;
type
TfrmMain = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ButtonClick(Sender: TObject);
private
// { Private declarations }
// public
// { Public declarations }
// end;
{var
frmMain: TfrmMain;
a,b:TB;
implementation }
{$R *.dfm}
{procedure TfrmMain.FormCreate(Sender: TObject);
begin
a:=TB.create(true,edit1);
b:=TB.create(True,edit2);
end;
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
freeandnil(a);freeandnil(b);
end;
procedure TfrmMain.ButtonClick(Sender: TObject);
var c :TB;
begin
if sender = Button1 then c :=a
else c:=b;
if c.Suspended then begin
c.Resume ; (sender as TButton).Caption :='暫停';
end else begin
c.Suspend ;(Sender as TButton).Caption :='開始';
end;
end;
end.
}
{
樓住的問題還沒有解決嗎?
我簡(jiǎn)單的寫了一下,已經(jīng)能實(shí)現(xiàn)你的功能;
unit CustomDBGridEX;
interface
uses
SysUtils, windows, Classes, Controls, Grids, DBGrids, Graphics;
type
TCustomDBGridEX = class(TCustomDBGrid)
private
protected
procedure DrawColumnCell(const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState); override;
public
property Canvas;
property SelectedRows;
published
property Align;
property Anchors;
property BiDiMode;
property BorderStyle;
property Color;
property Columns stored False; //StoreColumns;
property Constraints;
property Ctl3D;
property DataSource;
property DefaultDrawing;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FixedColor;
property Font;
property ImeMode;
property ImeName;
property Options;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property TitleFont;
property Visible;
property OnCellClick;
property OnColEnter;
property OnColExit;
property OnColumnMoved;
property OnDrawDataCell;
property OnDrawColumnCell;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEditButtonClick;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
property OnTitleClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TCustomDBGridEX]);
end;
procedure TCustomDBGridEX.DrawColumnCell(const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
inherited;
if DataSource.DataSet.RecNo mod 2 = 0 then
Canvas.Brush.Color := clred
else
Canvas.Brush.Color := clAqua;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end.
把上面的過程修改為下面會(huì)更好點(diǎn)! 呵呵!
procedure TCustomDBGridEX.DrawColumnCell(const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
inherited;
if DataSource.DataSet.RecNo mod 2 = 0 then
begin
Canvas.Brush.Color := clYellow;
Canvas.Font.Color := clBlack;
Canvas.TextRect(Rect, Rect.Left, Rect.Top, Column.Field.AsString);
end
else
begin
Canvas.Brush.Color := clWindow;
Canvas.Font.Color := clBlack;
Canvas.TextRect(Rect, Rect.Left, Rect.Top, Column.Field.AsString);
end;
end;
}
{
如何判斷一個(gè)對(duì)象是否已經(jīng)實(shí)例化?
我把一個(gè)對(duì)象Free后,為什么 (對(duì)象 = nil) 為 False呢
function GetM():TMyClass;
var r: TMyClass;
begin
r := TMyClass.Create;
Result := r;
end;
}
{
你可以先定義一個(gè)基類
//該類為純虛類,不用實(shí)現(xiàn)
TBase=class
public
procedure push(num:double);
function pop:double; virtual; abstract;
function top:double; virtual; abstract;
function count:integer; virtual; abstract;
end;
Tfloatstack=class(TBase)
private
farr:array of double;
public
procedure push(num:double);override;
function pop:double;override;
function top:double;override;
function count:integer;override;
end;
Tstringstack=class(TBase)
private
farr:array of string;
public
procedure push(num:string);override;
function pop:string;override;
function top:string;override;
function count:integer;override;
end;
}
{
我這有個(gè)動(dòng)態(tài)載入dxDBGrid列的函數(shù),也許對(duì)你有點(diǎn)作用:
procedure StoreGridColumn(const TableID: Word; DataGrid: TdxDBGrid);
var
i: Word;
aType: TdxSummaryType;
ColQuery: TSQLQuery;
begin
ColQuery := TSQLQuery.Create(Nil);
try
ColQuery.SQLConnection := dmMaster.ConnDB;
ColQuery.SQL.Text := 'select * from qps_column_note where (table_id = ' + IntToStr(TableID) +
') and (col_show = 1) order by col_show_id,auto_id';
for i := 0 to DataGrid.ColumnCount - 1 do
DataGrid.Columns[0].Destroy;
i := 0;
with ColQuery do begin
Open;
while not Eof do begin
if FieldByName('col_field_type').AsInteger = 0 then
DataGrid.CreateColumn(TdxDBGridColumn)
else if FieldByName('col_field_type').AsInteger = 1 then
DataGrid.CreateColumn(TdxDBGridDateColumn)
else if FieldByName('col_field_type').AsInteger = 2 then
DataGrid.CreateColumn(TdxDBGridCheckColumn)
else if FieldByName('col_field_type').AsInteger = 3 then
DataGrid.CreateColumn(TdxDBGridCurrencyColumn);
if FieldByName('col_has_foot').AsInteger > 0 then begin
aType := cstNone;
case FieldByName('col_foot_type').AsInteger of
0: aType := cstAvg;
1: atype := cstCount;
2: aType := cstMax;
3: aType := cstMin;
4: aType := cstNone;
5: aType := cstSum;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -