?? myfun.pas
字號:
myIniFile:=TiniFile.Create(FileName);
myIniFile.WriteString(Section,Ident,Value);
myIniFile.FreeInstance;
end;
{------------Write boolean------------}
procedure TFun.WriteIniFile(const FileName, Section, Ident: string;
Value: Boolean);
begin
myIniFile:=TiniFile.Create(FileName);
myIniFile.WriteBool(Section,Ident,Value);
myIniFile.FreeInstance;
end;
{------------Write Double------------}
procedure TFun.WriteIniFile(const FileName, Section, Ident: string;
Value: Double);
begin
myIniFile:=TiniFile.Create(FileName);
myIniFile.WriteFloat(Section,Ident,Value);
myIniFile.FreeInstance;
end;
{------------Write DateTime------------}
procedure TFun.WriteIniFile(const FileName, Section, Ident: string;
Value: TdateTime);
begin
myIniFile:=TiniFile.Create(FileName);
myIniFile.WriteDateTime(Section,Ident,Value);
myIniFile.FreeInstance;
end;
//______________________________________________________________________________
{procedure TFun.Destroy;
begin
inherited destroy;
end;}
//______________________________________________________________________________
{--------------------}
{得到日期對應的時間 }
{--------------------}
function TFun.GetWeekOfChina(dDay: TdateTime): string;
var
iwIndex:integer;
begin
iwIndex:=dayOfweek(dDay);
case iwIndex of
1:result:='星期天';
2:result:='星期一';
3:result:='星期二';
4:result:='星期三';
5:result:='星期四';
6:result:='星期五';
7:result:='星期六';
end;
end;
{--------------------------------------}
{星期一.....星期天: 1---7 }
{NND的外國人就喜歡用1表示星期天靠!不爽 }
{收以該位我們中國人習慣的1-7方式 }
{---------------------------------------}
function TFun.GetWeekOfNum(dDay: TdateTime): integer;
var
iwIndex:integer;
begin
iwIndex:=dayOfweek(dDay);
if iwIndex=1 then iwIndex:=7 else iwIndex:=iwIndex-1;
result:=iwIndex
end;
//________________________________________________________________________________________________________________________________________________________
{------------------------------------------------------}
{檢測findStr是否in mainStr,如果存在則返回True,否則False}
{------------------------------------------------------}
function TFun.IsStrInOtherStr(mainStr,FindStr: string): Bool;
begin
if strPos(pAnsiChar(mainStr),pAnsichar(FindStr))=nil
then
result:=False
else
result:=True;
end;
//______________________________________________________________________________
{--------------------------------------}
{利用GUID得到一個永遠不會重復的隨機序列}
{--------------------------------------}
function TFun.RandomNumByGUID:string;
var
ID: TGUID;
begin
if CreateGuid(Id) =0 then
begin
result:= GUIDToString(Id);
end;
end;
//______________________________________________________________________________
{------------------------------}
{ 判斷一個COM對像是否注冊過 }
{------------------------------}
function TFun.IsCOMClassRegistered(GUID: TGUID): Boolean;
var
COMGUID:String;
begin
with TRegistry.Create do
try
COMGUID:=GUIDToString(GUID);
RootKey:=HKEY_CLASSES_ROOT;
Result := OpenKey('\CLSID\'+COMGUID,False);
finally
Free;
end;
end;
//______________________________________________________________________________
{-------------------------------------}
{ 移去窗體的Title }
{-------------------------------------}
procedure TFun.ReMoveWinTitle(Form:Tform);
begin
SetWindowLong(Form.Handle,GWL_STYLE,
GetWindowLong(Form.Handle,GWL_STYLE) and not WS_CAPTION);
Form.Height:=Form.ClientHeight;
end;
//______________________________________________________________________________
{-------------------------------}
{判斷BDE是否安裝過。 }
{已安裝返回True,否則為false }
{-------------------------------}
function TFun.IsBDEInstalled: boolean;
var
reg:Tregistry;
s:string;
begin
s:='';
reg:=Tregistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey('SOFTWARE\Borland\Database Engine', False);
try
S:=reg.ReadString('CONFIGFILE01');
//BDE installed
finally
if S<>'' then result:=True else result:=False;
reg.CloseKey;
end;
end;
//______________________________________________________________________________
{系統小喇叭發聲}
procedure TFun.BeepEx(Freq: Word; MSecs: Integer);
begin
DoBleep(Freq,MSecs); //DoBeep用戶可調用過程頭
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//==============================================================================
// 虛擬鍵盤,是由于本人從事數據采集系統的
// 工業電腦用的是觸摸屏,寫了這個,用這方便。呵呵。
//從TstrigGrid繼承來的,,功能很有限,因為考慮到是用于6.5英寸的觸摸屏上。
//沒加其他標準的鍵盤功能。
//==============================================================================
{ TvirtualKeyBoard }
constructor TvirtualKeyBoard.Create(AOwner: TComponent);
const
KeyStr:array[0..2,0..13] of string=(('7','8','9','A','B','C','D','E','F','G','H','I','J','←'),
('4','5','6','','K','M','N','L','O','P','Q','R','','↙'),
('0','1','2','3','.','S','T','U','V','W','X','Y','Z',','));
var
i,j:integer;
begin
inherited Create(AOwner);
ScrollBars:=ssNone;
Height:=96;
Width:=438;
self.Show;
RowCount:=3;
ColCount:=14;
FixedCols:=0;
FixedRows:=0;
Ctl3D:=false;
DefaultColwidth:=30;
DefaultRowHeight:=30;
// ,10,[B],GB2312_CHARSET,clWindowText
// font.Style:=[fsBold];
font.Name:='宋體';
font.Size:=16;
font.Charset:=GB2312_CHARSET;
//-----------------
for i:=0 to RowCount-1 do
begin
for j:=0 to ColCount-1 do
begin
cells[j,i]:=KeyStr[i,j]
end;
end;
end;
{-------重載DrawCell著色----------}
procedure TvirtualKeyBoard.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited;
if (ACol<=2) or ((Arow=2) and (aCol in [13,3,4]))
or ((Arow=1) and (aCol in [12,13,3]))
or ((Arow=0) and (aCol in [13])) then
begin
canvas.Font.Color:=clwhite;
Canvas.Brush.Color:=clGray;
Canvas.FillRect(ARect);
end;
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]);
inherited DrawCell(ACol, ARow, ARect, AState);
end;
{----------------------------------}
{重載SelectCell處理 }
{當某一個格被選中時。處理按鍵值發送}
function TvirtualKeyBoard.SelectCell(ACol, ARow: Integer): Boolean;
var
KeyStr:string;
keyHex:word;
// fn:Tfun;
begin
// Fn:=Tfun.Create(self);
KeyStr:=cells[aCol,aRow];
if assigned(FVkeyDown) then OnSelectCell(self,keyStr);
if FSendHandle<>nil then
begin
if KeyStr='' then keyHex:=0 else keyHex:=ord(keystr[1]);
case AnsiIndexStr(KeyStr,[',','.','↙','←']) of
0:keyHex:=188;
1:keyHex:=VK_DECIMAL;
2:keyHex:=vk_return;//回車
3:keyHex:=VK_Back;//退格鍵
end;
DoBleep(500,100);
Fn.SendKey(FSendHandle.Handle,keyHex);
end;
// fn.Free;
result:=true
end;
procedure TvirtualKeyBoard.SetSendHandle(Control: TWinControl);
begin
if FSendHandle <> Control then FSendHandle := Control;
end;
{TExChart }
//==============================================================================
// TExChart:增強型的TChar組件,因為數據采集系統中老用到TChart,
//但標準的TChart功能上有點那個,HOHO,就加強加強.實際項目中用的十分方便
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//==============================================================================
procedure TExChart.DrawMouseLine(var Message: Tmessage);
var
// Fn:Tfun;
ChartIndex:integer;
MousePos:Tpoint;
begin
if FDrawMouseLineFlag then
begin
// Fn:=Tfun.Create(self);
if self.SeriesCount>0 then
begin
ChartIndex:=Fn.ChartMoveLine(self,message.LParamLo,FDrawMouseLineColor);
if (Series[0].Count>0) and (ChartIndex<>-1) then
begin
MousePos.X:=message.LParamLo;
MousePos.Y:=Message.LParamHi;
//FYLableDraw是用戶表示FYLable顯示的flag
if FYLableDraw then
Canvas.TextOut(3,3,FYLableCaption+FloatTostr(self.Series[0].YValue[ChartIndex])+FYLableunit);
if assigned(FChartYIndex) then
OnMouseMove(nil,ChartIndex,MousePos.X,MousePos.Y,Series[0].YValue[ChartIndex]);
end;// if (Series[0].Count>0) and (ChartIndex<>-1) then
// Fn.Free;
end;//if self.SeriesCount>0 then
end;//if FDrawMouseLineFlag then
end;
//------------------------------------------------------------------------------
procedure TExChart.SetDrawMouseLineFlag(Flag: Boolean);
begin
if FDrawMouseLineFlag<>Flag then FDrawMouseLineFlag:=Flag
end;
//------------------------------------------------------------------------------
procedure TExChart.SetDrawMouseLineColor(Color: TColor);
begin
if FDrawMouseLineColor<>Color then FDrawMouseLineColor:=Color
end;
//------------------------------------------------------------------------------
{設置用與現實Y坐標上的值得lable的名字}
procedure TExChart.SetYLableCaption(caption:String);
begin
if FYLableCaption<>caption then
FYLableCaption:=caption;
end;
//______________________________________________________________________________
procedure TExChart.SetYLableUnit(UnitValue: String);
begin
if FYLableUnit<>UnitValue then
FYLableUnit:=UnitValue;
end;
//------------------------------------------------------------------------------
procedure TExChart.SetYLableDraw(Flag: boolean);
begin
if Flag<>FYLableDraw then FYLableDraw:=Flag
end;
{-----------------------------}
{創建時的默認設置 }
{-----------------------------}
constructor TExChart.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDrawMouseLineFlag:=True;
FDrawMouseLineColor:=clBlue;
FYLableDraw:=True;
FYLableCaption:='電壓:';
FYLableUnit:='(V)';
end;
{==============================================================================}
{ TExEdit}
{將回車轉為Tab}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{===============================================================================}
constructor TExEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
LabelPosition:= lpLeft;
end;
//------------------------------------------------------------------------------
procedure TExEdit.SetCaption(const Value: string);
begin
FCaption := Value;
self.EditLabel.Caption:=FCaption;
end;
//------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -