日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

delphi學習 | 學步園

 佚名2016 2016-08-04

 1.[Error] DCansactionIformationManagement.pas(171): String literals may have at most 255 elements
[Fatal Error] DCMain.pas(32): Could not compile used unit 'DCansactionIformationManagement.pas'
報錯:‘不正常定義了參數(shù)。提供了不一致或不完整信息’
解決方法:語法
數(shù)據(jù)定義要一致
2.Edit19.Text:= FieldbyName('SQTcost') 讀取數(shù)據(jù)

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ComCtrls, TeeProcs, TeEngine, Chart, DbChart,
  ExtCtrls, Series

3.maskedit1.text:=datetostr(Date()); 獲取當前日期
加一個timer控件,system里面有,是一塊表的樣子,呵呵。
雙擊進入ontimer事件,然后寫下你的代碼
Statusbar1.Panels[0].Text:='系統(tǒng)日期:'+datetostr(Now);
Statusbar1.Panels[1].Text:='系統(tǒng)時間:'+timetostr(Now);

OPEN只用來SELECT
EXECSQL 用所有的
prepared告訴服務器準備要干活了

有返回一些記錄的用OPEN
不需要返回記錄的用EXECSQL
就是說一般用select 要用OPEN
而像insert .drop等只要用ExecSql

4.GetCursorValues(tmpX,tmpY);  { <-- get values under mouse cursor }
      Label1.Caption:=GetVertAxis.LabelValue(tmpY)+
                      ' '+
                      GetHorizAxis.LabelValue(tmpX);獲取坐標值

5.滾動 代碼  procedure TDemoForm.SpeedButton1Click(Sender: TObject);
begin
  HorizScroll(10);
end;

procedure TDemoForm.SpeedButton4Click(Sender: TObject);
begin
  HorizScroll(-10);
end;

procedure TDemoForm.SpeedButton2Click(Sender: TObject);
begin
  VertScroll(-10);
end;

procedure TDemoForm.SpeedButton3Click(Sender: TObject);
begin
  VertScroll(10);
end;

6.清除系列:if dbchart1.SeriesCount>=0 then
  begin
  for i:=0 to dbchart1.SeriesCount-1 do
    begin
      dbchart1.Series[i].Clear;
    end;
7.
  table2:=ttable.Create(self);
  table2.DatabaseName:='MS Access Database';
  table2.TableName:='趨勢分析法';
  series1.DataSource:=table2;
  series1.XLabelsSource:='年份';

  series1.YValues.ValueSource:='預測用電量';
  Table2.open;
end;
8.

  if radiobutton1.Checked then
    try
    with DataModuleADO.ADOQuery1 do
     begin
      SQL.Clear;
      SQL.Add('insert into 回歸分析法(年份,實際用電量,年國內(nèi)生產(chǎn)總值,預測用電量,該年人口,誤差,算法,備注)'+
                ' values (:年份,:實際用電量,:年國內(nèi)生產(chǎn)總值,:預測用電量,:該年人口,:誤差,:算法,:備注)');
      Parameters.ParamByName('年份').value := ComboBox1.text;
      Parameters.ParamByName('實際用電量').value := '';
      b:=StrToInt(Parameters.ParamByName('年國內(nèi)生產(chǎn)總值').value );
      c:=StrToInt(Parameters.ParamByName('該年人口').value );
      Parameters.ParamByName('預測用電量').value :=-3.9848*b+0.0727+0.10307*c;
      Parameters.ParamByName('誤差').value := '';
      Parameters.ParamByName('算法').value := '回歸分析法';
      Parameters.ParamByName('備注').value := '';

      ExecSQL;
     end;
    Form22_DCfuheyuce_huiguifenxifa.show(Sender);

    except
    MessageDlg('計算出錯',mtError,[mbok],0);
    end;
9;
1.整型
一個整型數(shù)據(jù)用來存放整數(shù)。Turbo Pascal支持五種預定義整型,它們是shortint(短整型)、 integer(整型)、 longint(長整型)、 byte(字節(jié)型)和 word(字類型),Turbo Pascal分別用相同的名字作為他們的表識符。每一種類型規(guī)定了相應的整數(shù)取值范圍以及所占用的內(nèi)存字節(jié)數(shù)。

類型數(shù)值范圍占字節(jié)數(shù)格式

shortint-128..127 1 帶符號8位

integer-32768..32767 2 帶符號16位

longint-2147483648..2147483647 4 帶符號32位

byte0..2551無符號8位word0..655352 無符號16位

說明:integer-32768..32767 2(占字節(jié)數(shù)) 帶符號16位(格式)

Turbo Pascal規(guī)定了兩個預定義整型常量表識符maxint和maxlongint,他們各表示確定的常數(shù)值,maxint為32767, maxlongint為2147483647,他們的類型分別是integer 和longint。

2.實型
一個實型數(shù)據(jù)用類存放實數(shù)。Turbo Pascal支持五種預定義實型,它們是real(基本實型)、 single(單精度實型)、double(雙精度實型)、extended(擴展實型)、comp(裝配實型),Turbo Pascal分別用相同的名字作為他們的標識符。每一種類型規(guī)定了相應的實數(shù)取值范圍、所占用的內(nèi)存字節(jié)數(shù)以及它們所能達到的精度。

類型數(shù)值范圍占字節(jié)數(shù)有效位數(shù)

real2.9e-39..1.7e38 6 11..12

single1.5e-45..3.4e38 4 7..8

double5.0e-324..1.7e308 8 15..16

extended3.4e-4951..1.1e4932 10 19..20

comp-2**63+1..2**63-1 8 19..20

說明real2.9e-39..1.7e38 6(占字節(jié)數(shù)) 11..12(有效位數(shù))

Turbo Pascal支持兩種用于執(zhí)行實型運算的代碼生成模式:軟件仿真模式和80x87浮點模式。除了real可以在軟件仿真模式下直接運行以外,其他類型必須在80x87浮點模式下運行,要在程序頭加編譯指示{$N+,E+}

3.布爾型
一個布爾型數(shù)據(jù)用來存放邏輯值(布爾值)。布爾型的值只有兩個:false和true,并且false的序號是0,true的序號是1。false 和true都是預定義常數(shù)標識符,分別表示邏輯假和邏輯真。boolean是布爾型的類型標識符。

4.字符型
字符型用char作為標識符。字符型必須用單引號括起來,字母作為字符型時,大小寫是不等價的,并且字符型只允許單引號中有一個字符,否則就是字符串。

 

 

10.整數(shù)到字符串 IntTostr() 字符串=IntTostr(整數(shù))
字符串到整數(shù) strToInt()
字符串到小數(shù) StrToFloat()
小數(shù)到字符串 FloatToStr()  修改庫胡總的數(shù)據(jù)時候要數(shù)據(jù)類型~~~
11
    編寫代碼:
     procedure TForm1.Button1Click(Sender: TObject);
      begin
         edit1.Text:=IdIPWatch1.LocalIP;
       end;

  OK!按下F9功能鍵,運行程序,點擊button看一下edit1中是不是已經(jīng)顯示了本機的IP

地址了?
12.
     平常使用軟件的時候,經(jīng)常聽到一些程序居然有背景音樂.呵呵,邊工作學習,邊聽音樂,真是一大樂趣!

  在delphi編程中如何實現(xiàn)播放背景音樂呢?我們都知道TMediaPlayer控件可以播放音樂,但我們現(xiàn)在不用它,我們用WINDOWS為我們提供的API函數(shù)來播放音樂,方法如下:

1 .首先需要在uses部分加入mmsystem.

2 .為播放按鈕寫代碼:

MCISendString(OPEN e:/1.MID TYPE SEQUENCER ALIAS NN, , 0, 0);
MCISendString(PLAY NN FROM 0, , 0, 0);
MCISendString(CLOSE ANIMATION, , 0, 0);

3.為停止按鈕寫代碼:

MCISendString(OPEN e:/1.MID TYPE SEQUENCER ALIAS NN, , 0, 0);
MCISendString(STOP NN, , 0, 0);
MCISendString(CLOSE ANIMATION, , 0, 0);

其中

NN為自定義名稱標志,e:/1.mid為要播放的音樂文件.

13.
      本文主要講解了如何控制數(shù)據(jù)庫關鍵字的重復輸入,這里我們舉一個簡單的例子來說明。為了方便我們就使用Delphi自帶的數(shù)據(jù)庫DBDEMOS,它是Paradox型的數(shù)據(jù)庫,其中表employee.db具有關鍵字EmpNo。

     Table1的DataBaseName是DBDEMOS ,TableName是employee.db,Active設為True。DataSource1的DataSet是Table1。DBNavigator1和DBGrid1的DataSource是DataSource1。

     下面我們就要寫Table的OnPostError事件:當出現(xiàn)重復的關鍵字時,首先要提示用戶,然后取消此次操作。這個事件是在修改或向數(shù)據(jù)庫插入記錄時產(chǎn)生異常時才響應的。具體代碼如下:

procedure TForm1.Table1PostError
(DataSet: TDataSet; E: EDatabaseError;
  var Action: TDataAction);
  begin
    if (E is EDBEngineError) then
if (E as EDBEngineError).Errors
[0].Errorcode = eKeyViol then
    begin
      MessageDlg('出現(xiàn)重復記錄!',
 mtWarning, [mbOK], 0);
      Table1.Cancel;
      Abort;
    end;
end;

     說明:
     1. 通過EDBEngineError異??梢垣@得描述數(shù)據(jù)庫驅(qū)動錯誤的詳細信息。當EDBEngineError異常產(chǎn)生時,就會生成一個EDBEngineError對象,這個EDBEngineError對象包含有異常的錯誤信息,可以用程序進行分析,從而決定要完成的操作。

     2. 上面程序的Errorcode是BDE的錯誤代碼,是一個word類型的變量,我們還需要定義它,定義如下

  const
  eKeyViol = 9729;
14.
  uses   Math;  
   
  Power(X,   Y);

15.
如何讓數(shù)據(jù)塊以不同顏色顯示(除了TPieSeries是以不同顏色顯示數(shù)據(jù)塊外,其它的默認都是紅色),并動態(tài)改變標題與頁角及Y坐標的標題

 

--------------------------------------------------------------------------------

 

procedure TForm1.Button5Click(Sender: TObject);
begin
  Chart1.Series[0].ColorEachPoint:=True; //數(shù)據(jù)塊不同色
  Chart1.LeftAxis.Title.Caption:='產(chǎn)品銷售表';//Y坐標標題
  Chart1.Title.Text.Clear;
  Chart1.Title.Text.Add('哪個月份的銷售記錄');//圖表標題
  Chart1.Foot.Text.Add('圖表的說明文字'); //頁腳內(nèi)容
end;

1,Delphi中提供了大量的決策圖表控件

Decision->決策,決斷

Cube->立方

Chart->圖表

Series->系列

TeeChart->T型圖表

Gallery->圖庫

Axis->軸線

Gradient->漸變

Legend->圖例 傳奇

 

--------------------------------------------------------------------------------

 

Delphi7中

TChart組件---------->Additional

TDBChart組件----------->Data Controls

Decision Cube組件組里有一整套

TVTChart->ActiveX

ChartFx->ActiveX

--------------------------------------------------------------------------------

 

圖表(Chart)組件的屬性絕大多數(shù)一樣,用法也一樣

1,去掉Chart的3D效果 View3D->False

2,標題文字 Title->Text 有字體屬性

3,底部文字 Foot->Text 有字體屬性

4,去掉軸線->AxisVisible->false

5,BottomAxis   RightAxis LeftAxis TopAxis->上下左右的坐標線

6,Frame->Mode->區(qū)域色與底色的模式

7,Frame->Style->邊框樣式

8,Gradient->漸變設置

9,很多屬都可在雙擊Chart進行設置

10,MaxPointsPerPage->每頁中容納的最大數(shù)據(jù)量->如果為0則表示全部數(shù)據(jù)都裝在一頁中,當顯示的數(shù)據(jù)較多時,要設這個屬性,只有設了這個屬性,才能把數(shù)據(jù)分頁顯示!

---------------------------------------------

設置這些就可以得到一個帶漸變的Panel

------------------------------------------------------

如何動態(tài)增加一個圖表?

--------------------------------------------------------------------------------

 

注意:TChart, TDBChart只是一個圖表的容器控件,繼承自Panel,而真正的圖表是一個不可視的類

-----------------------------------------------------------------------------------------

定義條型(反映不同數(shù)據(jù)的變化情況,如,每月,每天銷售的各大類情況,哪類銷售最多,那類銷售最少) 

var a:TBarSeries;

定義餅型(主要用于不同數(shù)據(jù)所占的比例,如銷售中,各大類的銷售情況)

var a:TPieSeries;

定義折線型(反映同一數(shù)據(jù)的變化,如每天,每月的銷售變化, 這樣可以看出,哪天,哪月的銷售情況最好,最不好)

var a:TLineSeries

注意必須引用Series

 

--------------------------------------------------------------------------------

 

如何給一個圖表賦值并顯示在Chart中???

 

--------------------------------------------------------------------------------

 

procedure TForm1.Button2Click(Sender: TObject);
var
  a:TLineSeries;
begin
  a:=TLineSeries.Create(a);
  Chart1.AddSeries(a);
  a.AddArray([1,3,5,9,4,2])
end;

 

--------------------------------------------------------------------------------

 

如何在已顯示出來的圖表中增加數(shù)據(jù)?

 

--------------------------------------------------------------------------------

 

方法1

procedure TForm1.Button1Click(Sender: TObject);
begin
   Chart1.Series[0].AddXY(12,20,'新加的',clLime);

//12->X軸的坐標  20->Y軸的坐標  Clime是顏色
                                           
end;

 

--------------------------------------------------------------------------------

 

方法2

procedure TForm1.Button3Click(Sender: TObject);
begin
  Chart1.Series[0].Add(14,'打印機',clTeeColor);
  Chart1.Series[0].Add(18,'主板',clTeeColor);
  Chart1.Series[0].Add(23,'顯示器',clTeeColor);

end;

 

--------------------------------------------------------------------------------

 

如何動態(tài)改變圖表背景的漸變

 

--------------------------------------------------------------------------------

 

procedure TForm1.Button4Click(Sender: TObject);
begin
   Chart1.Gradient.Visible:=True;
   Chart1.Gradient.EndColor:=clTeal;
   Chart1.Gradient.StartColor:=clWhite;
end;

 

--------------------------------------------------------------------------------

 

如何讓數(shù)據(jù)塊以不同顏色顯示(除了TPieSeries是以不同顏色顯示數(shù)據(jù)塊外,其它的默認都是紅色),并動態(tài)改變標題與頁角及Y坐標的標題

 

--------------------------------------------------------------------------------

 

procedure TForm1.Button5Click(Sender: TObject);
begin
  Chart1.Series[0].ColorEachPoint:=True; //數(shù)據(jù)塊不同色
  Chart1.LeftAxis.Title.Caption:='產(chǎn)品銷售表';//Y坐標標題
  Chart1.Title.Text.Clear;
  Chart1.Title.Text.Add('哪個月份的銷售記錄');//圖表標題
  Chart1.Foot.Text.Add('圖表的說明文字'); //頁腳內(nèi)容
end;

 

17;自由改變圖形
  var      
      bar:   TbarSeries;  
      pie:   TpieSeries;  
  begin  
  //柱形圖    
      Title.Text.Clear;  
        Title.Text.Add('表名稱');                          
        bar   :=   TbarSeries.Create(nil);  
        bar.Clear;  
        bar.ParentChart   :=   DBChart1;    
        bar.add(123,'name');  
  //餅圖  
      if   DBchart1.SeriesCount   >   0   then  
          DBchart1.Series[0].Free;//如果表中有圖型將先FREE  
       
        Title.Text.Clear;  
        Title.Text.Add('表名稱');                          
        pie   :=   TbarSeries.Create(nil);  
        pie.Clear;  
        pie.ParentChart   :=   DBChart1;    
        pie.add(123,'name');  
   
   
  end;

18:
    if DBchart1.SeriesCount>0   then
   DBchart1.Series[0].Free;
  清楚圖表
19 ;
   窗體的基本方法
(1)Close方法
     該方法的執(zhí)行將關閉窗體,其基本語法為:Form1.Close;
(2)Hide方法
    
該方法將窗體隱藏起來,其基本語法為:Form1.Hide;
(3)Release方法
   
 該方法將關閉窗體并釋放窗體及窗體中組件所占用的內(nèi)存。
(4)Show方法
   

 該方法將顯示窗體或?qū)⒋绑w置前,使用Show方法可以在窗體不關閉的情況下切換到調(diào)用它的窗體。值得注意的是:
在調(diào)用其它窗體時,首先要將被調(diào)用窗體的單元引用到調(diào)用單元中。
(5)ShowModal方法
     該方法將顯示一個模式窗體(
即不能夠切換到其它窗體,如需切換必須關閉這個窗體)。
20,
 7)TabOrder屬性
     TabOrder屬性用來指定按Tab鍵時獲得焦點的順序。TabOrder屬性的取值類型為Integer,從0開始。
TabOrder屬性的設置適用于所有能夠獲得焦點的組件,可以在組件上單擊鼠標右鍵,在彈出菜單上選擇“Tab鍵順序…”來設置Tab鍵順序

21,Label組件的常用事件:
(1)OnMouseEnter事件
    
當鼠標移動到標簽上時觸發(fā)該事件。
(2)OnMouseLeave事件
   
 當鼠標離開標簽時觸發(fā)該事件。22
Active屬性用來說明數(shù)據(jù)庫文件的打開狀態(tài)。應用Active屬性來決定及設定一個數(shù)據(jù)集組件與

數(shù)據(jù)庫數(shù)據(jù)之間的關系。當Active屬性值為True時,表明數(shù)據(jù)集是打開的,數(shù)據(jù)集組件可以對

數(shù)據(jù)庫進行讀寫操作,否則表示數(shù)據(jù)集是關閉的,數(shù)據(jù)集組件不能從數(shù)據(jù)庫讀取數(shù)據(jù),也不能
向數(shù)據(jù)庫中寫數(shù)據(jù)。應用程序在改變其它影響數(shù)據(jù)庫狀態(tài)或在應用程序中顯示數(shù)據(jù)的組件狀態(tài)
的屬性之前,必須先將Active屬性設置為False。
23
 Query1.Fields[0].DisplayLabel:=’第一列’
使用方法FieldByName按照字段的名字來訪問,如顯示studentinfo表中Name屬性值只需要使
用代碼Edit1.text:=Table1.FieldByName(‘Name’).AsString;
24
 try…except…end
25
  i : integer;
  begin
    for i :=0 to ListView1.Items.Count-1 do
    if ListView1.Items[i].Selected then
       begin
     if ListView1.Items[i].SubItems.Strings[7]='2' then
        begin
        a:=ListView1.Items[i].Caption;
        b:=ListView1.Items[i].SubItems.Strings[0]; //行 列
26
  DataModule3.adoquery1.close;   
            DataModule3.adoquery1.SQL.clear;
            DataModule3.adoquery1.SQL.add ('select  密碼   from  login where 用戶名='''+s+''' ');
            DataModule3.adoquery1.Open;
            m:=DataModule3.adoquery1.FieldByName('密碼').Asstring;
            DataModule3.adoquery2.close;
            DataModule3.adoquery2.SQL.clear;
            DataModule3.adoquery2.SQL.add ('select  類別 from  login where 用戶名='''+s+''' ');
            DataModule3.adoquery2.Open;
            n:=DataModule3.adoquery2.FieldByName('類別').Asstring;
27
 const
TVS_CHECKBOXES = $00000100;

procedure SetComCtrlStyle(WinCtrl: TWinControl; Value: Integer; UseStyle: Boolean);
var
Style: Integer;
begin
  if WinCtrl.HandleAllocated then
  begin
    Style := GetWindowLong(WinCtrl.Handle, GWL_STYLE);
    if not UseStyle then
    Style := Style and not Value
    else Style := Style or Value;
    SetWindowLong(WinCtrl.Handle, GWL_STYLE, Style);
  end;
end;

 

然后 在 OnCreate 調(diào)用:

SetComCtrlStyle(TreeView1, TVS_CHECKBOXES, True);
 

 

或者干脆簡單點,一句話完事:

SetWindowLong(TreeView1.Handle, GWL_STYLE, GetWindowLong(TreeView1.Handle, GWL_STYLE) or $00000100);
 
28
   for i:=dbChart1.SeriesCount-1 downto 0 do
         begin
         dbChart1.Series[i].Free;
29
rocedure TFrmBmGzxmTj.Button1Click(Sender: TObject);
var
  i:integer;
  xls :OleVariant;
begin
  if ((DM_GSGL.QryGzxmTj.active=false) or (DM_GSGL.QryGzxmTj.RecordCount=0)) then
  begin
    MessageDlg('沒有數(shù)據(jù),輸出失??!',mtError, [mbYes],0);
    Exit;
  end;
  xls:=CreateOleObject('Excel.Application');
  xls.WorkBooks.add;
  xls.Visible:=true;
  xls.cells(1,2):='從'+FormatDateTime('yyyymmdd',DtpDate1.Date)+'到'+FormatDateTime('yyyymmdd',DtpDate2.Date);
  xls.cells(2,1):='工號';
  xls.cells(2,2):='姓名';
  xls.cells(2,3):='人員類別';
  xls.cells(2,4):='總工時';
  i:=3;
  with DM_GSGL.QryGzxmTj do
  begin
    First;
    while not Eof do
    begin
      xls.cells(i,1):=Fieldbyname('工號').asstring;
      xls.cells(i,2):=Fieldbyname('姓名').asstring;
      xls.cells(i,3):=Fieldbyname('人員類別').asstring;
      xls.cells(i,4):=Fieldbyname('總工時').asstring;
      i:=i+1;
      Next;
    end;
  end;
  i:=i+1;
  xls.cells(i,1):='工時合計';
  xls.cells(i,4):=label4.Caption;
end;
30
 procedure TForm1.Button1Click(Sender: TObject);
begin
  Chart1.Series[0].AddXY(12,20,'新加的',clLime);

//12->X軸的坐標 20->Y軸的坐標 Clime是顏色
  
end;

 

方法2

procedure TForm1.Button3Click(Sender: TObject);
begin
  Chart1.Series[0].Add(14,'打印機',clTeeColor);
  Chart1.Series[0].Add(18,'主板',clTeeColor);
  Chart1.Series[0].Add(23,'顯示器',clTeeColor);

end;

 

如何動態(tài)改變圖表背景的漸變

 

procedure TForm1.Button4Click(Sender: TObject);
begin
  Chart1.Gradient.Visible:=True;
  Chart1.Gradient.EndColor:=clTeal;
  Chart1.Gradient.StartColor:=clWhite;
end;

 

如何讓數(shù)據(jù)塊以不同顏色顯示(除了TPieSeries是以不同顏色顯示數(shù)據(jù)塊外,其它的默認都是紅色),并動態(tài)改變標題與頁角及Y坐標的標題

 

procedure TForm1.Button5Click(Sender: TObject);
begin
  Chart1.Series[0].ColorEachPoint:=True; //數(shù)據(jù)塊不同色
  Chart1.LeftAxis.Title.Caption:='產(chǎn)品銷售表';//Y坐標標題
  Chart1.Title.Text.Clear;
  Chart1.Title.Text.Add('哪個月份的銷售記錄');//圖表標題
  Chart1.Foot.Text.Add('圖表的說明文字'); //頁腳內(nèi)容
end;

 

效果如下:

 

 

 

數(shù)據(jù)太多了,想翻頁顯示怎么做?

 

1,設置Chart->MaxPointsPerPage(每頁的最大數(shù)據(jù)量)->只有設置了這個置才可能分頁,如果是0表示,全部數(shù)據(jù)都在一頁上

2,可以使用點擊左右坐標進行上下翻頁也可以點擊鼠標的左右鍵進行翻頁
-----------------
procedure TForm1.Chart1ClickBackground(Sender: TCustomChart;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button=mbLeft then Chart1.NextPage;
  if Button=mbRight then Chart1.PreviousPage;
end;

 

如何標顯特殊數(shù)據(jù)(當點特殊數(shù)據(jù)時以不同顏色進行顯示)

 

procedure TForm1.Chart1ClickSeries(Sender: TCustomChart;
  Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Series.ValueColor[ValueIndex]:=clRed;
end;

 

動態(tài)圖表分析技術

 

DBChart

-------------------------------

動態(tài)圖表的連接方式分2種

①手工方式連接數(shù)據(jù)庫

②運用DBChart屬性,在動行時動態(tài)連接數(shù)據(jù)庫

---------------------------------------

1,DBChart對于數(shù)據(jù)是只圖的,所以他連接數(shù)據(jù)庫表,關不是直接掛連ACCESS組件,而是直接連接DataSet,Table,Query,ClientDataSet這樣的數(shù)據(jù)集組件

2,首先要設好數(shù)據(jù)據(jù)組件的連接,再設置DBChart與數(shù)據(jù)組件連接

方法如下:

①雙擊DBChart->Series->設置標題,X的數(shù)據(jù),Y(Bar)的數(shù)據(jù)

 

②,如果是在動行時設置是設置是設置DBChart的如下屬性

DBChart->DataSet

DBChart->XLabelSource

DBChart->XValues

DBChart->YValues

----------------------------

procedure TForm1.Button3Click(Sender: TObject);
begin
  DBChart1.Series[0].DataSource:=ADODataSet1;
  DBChart1.Series[0].XLabelsSource:='酒水名稱';
  DBChart1.Series[0].XValues.ValueSource:='單價';//寫的都是字段名稱
  DBChart1.Series[0].YValues.ValueSource:='單價';
end;

----------------------------------------

 

如何讓DBChart自動更新數(shù)據(jù)顯示

 

1,手動更新需設置DBChart->AutoRefresh->Rrue或False

2,自動更新設置DBChart->RefreshInterval的值,以秒為單位,每隔多少秒更新一次數(shù)據(jù)
30 listbox的用法
 var
  i:Integer;
begin
  for i :=0 to ListBox1.Count-1 do
  begin
    if ListBox1.Selected[i] then
    ListBox2.Items.Add(ListBox1.Items.Strings[i]);
  end;
  ListBox1.DeleteSelected;//增加后刪除所選的記錄
end;
31
 delphi listbox 添加數(shù)據(jù)
 懸賞分:10 - 解決時間:2009-2-25 16:23
怎么把 數(shù)據(jù)庫 當中的某一列stu_id數(shù)據(jù)全部添加到listbox當中啊
var s:string;
 close;
 sql.Clear;
 sql.Add('select stu_id  from students');
 s:=fieldbyname('nnbianhao').AsString;
 open;
 first;
 while not EOF  do
 begin
 ListBox1.Items.Add(s);
 next;
 end ;
32
 Chart.Free;  
 Series.Free;
33 dbchart的使用
ADOQuery1.Active:=True;
DBChart1.Series[0].DataSource:=ADOQuery1;
DBChart1.Series[0].XLabelSource:='FiledName';
DBChart1.Series[0].YValues.ValueSource:='FieldName';

2.切換圖表類型
tmpChart:=DBChart1.Series[0];
ChangeSeriesType(tmp,TLineSeries);
tmpChart.Active:=True;
tmpChart.RefreshSeries;

3.設置分頁
DBChart1.ScaleLastPage:=true;
DBChart1.MaxPointsPerPage:=10;

DBChart1.Page:=1; 代碼實現(xiàn)
DBChart1.PreviousPage;
DBChart1.NextPage;
DBChart1.Page:=NumPages;

4.導出圖表
SaveToBitmapFile(FileName);

5.打印圖表
uses TeePrevi;
ChartPreview(Parent,DBChart1);
TeePreview(Parent,DBChart1);

6.數(shù)據(jù)源
ADODataSet1.CreateDataSet;
AdoDataSet1.Insert;
AdoDataSet1.FieldByName('Value').AsFloat:=200000;
AdoDataSet1.FieldByName('Info').AsString:='05-02';
AdoDataSet1.Post;  

33
  ado:
 ADOConnection1.GetTableNames
  for i:= 0 to ADOQuery1.FieldCount-1
       adoQuery1.Fields[i].FullName;
....

bde:
34
 桂A-撈佬(371775431) 11:27:07
怎樣在stringgrid中導入Excel
川A-小鯉魚(252966040) 11:29:09
用個讀寫EXCEL的控件
川A-小鯉魚(252966040) 11:29:27
讀出EXCEL的CELL值,并加入StringGrid中就行了
35》
  formatdatetime('aaa',now);//當前星期  
  formatdatetime('c',now);//以2003-8-16   23:03:23的形式顯示當前日期和時間  
  formatdatetime('d',now);//顯示當前的日期   1被顯示成1  
  formatdatetime('dd',now);//顯示當前的日期   1被顯示成01  
  formatdatetime('ddd',now);//顯示當前的星期  
  formatdatetime('ddddd',now);//以2003-8-1的形式顯示年月日  
  formatdatetime('dddddd',now);//以2003年8月1日的形式顯示年月日  
  formatdatetime('dddddd   ddd',now);//以‘2003年8月1日   星期五’的形式顯示年月日及星期  
  formatdatetime('e',now);//顯示年的最后一位2003被顯示成3  
  formatdatetime('ee',now);//顯示年的最后二位2003被顯示成03  
  formatdatetime('eee',now);//顯示年2003被顯示成2003  
  formatdatetime('h',now);//顯示小時1被顯示成1  
  formatdatetime('hh',now);//顯示小時1被顯示成01  
  formatdatetime('m',now);//顯示月1被顯示成1  
  formatdatetime('mm',now);//顯示月1被顯示成01  
  formatdatetime('mmm',now);//以‘八月’的形式顯示月份  
  formatdatetime('n',now);//顯示當前分鐘1被顯示成1  
  formatdatetime('nn',now);//顯示當前分鐘1被顯示成01  
  formatdatetime('s',now);//顯示當前秒1被顯示成1  
  formatdatetime('ss',now);//顯示當前秒1被顯示成01  
  formatdatetime('t',now);//以1:05的形式顯示小時和分鐘  
  formatdatetime('tt',now);//以1:06:13的形式顯示小時和分鐘和秒  
  formatdatetime('y',now);////顯示年的最后二位2003被顯示成03  
  formatdatetime('yyy',now);//顯示年2003被顯示成2003  
  formatdatetime('z',now);//顯示當前毫秒1被顯示成1  
  formatdatetime('zz',now);//顯示當前毫秒1被顯示成01  
  formatdatetime('zzz',now);//顯示當前毫秒1被顯示成001

         while not DataModuleADO.ADOQuery1.eof do
    begin
    for i:=0 to DataModuleADO.ADOQuery1.DataSet.Field.Count-1 do
    begin
    a                      Single
    end;

  Next;

  begin
          SetLength(strlist,DBGrid1.DataSource.DataSet.FieldCount-1);
          for   j:=0  to  DBGrid1.DataSource.DataSet.FieldCount-1   do
          strlist[j]:=DBGrid1.DataSource.DataSet.Fields[j].AsString;
         end;

本實例要在窗體上直接繪制正弦曲線,為了防止窗口切換的過程中會輸出不完整的圖形,因此繪制圖形的關鍵代碼都放在了窗體的OnPaint過程中,代碼如下:
procedure TForm1.FormPaint(Sender: TObject);
var
 x: Integer;
 y,a: Double;
begin
 Canvas.Pen.Width:=3;
 Canvas.MoveTo(0,Trunc(self.ClientHeight/2));
 for x := 0 to self.ClientWidth do
 begin
  a := (x/self.ClientWidth) * 2 * Pi;
  y := Sin(a);
  y := (1-y)*self.ClientHeight/2;
  Canvas.LineTo(Trunc(x), Trunc(y));
 end;
end;
  程序首先設置了窗體的Canvas對象中畫筆的寬度,并且把繪圖的起點移動到了窗體中(0,Trunc(self.ClientHeight/2))的位置。然后通過一個循環(huán)中的a:= (x/self.ClientWidth)*2*Pi語句將一個正弦周期內(nèi)的角度值轉(zhuǎn)換為弧度值,并且把正弦計算后的結(jié)果存儲在變量y中。最后,循環(huán)中的Canvas.LineTo(Trunc(x), Trunc(y))語句就會在窗體上繪制出連續(xù)的正弦曲線。
  程序代碼如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
 TForm1 = class(TForm)
 procedure FormPaint(Sender: TObject);
 procedure FormResize(Sender: TObject);
 procedure FormCreate(Sender: TObject);
private
 { Private declarations }
public
 { Public declarations }
end;
var
 Form1: TForm1;
 implementation
 {$R *.dfm}
 procedure TForm1.FormPaint(Sender: TObject);
var
 x: Integer;
 y,a: Double;
begin
 Canvas.Pen.Width:=3;
 Canvas.MoveTo(0,Trunc(self.ClientHeight/2));
 for x := 0 to self.ClientWidth do
 begin
  a := (x/self.ClientWidth) * 2 * Pi;
  y := Sin(a);
  y := (1-y)*self.ClientHeight/2;
  Canvas.LineTo(Trunc(x), Trunc(y));
 end;
end;
procedure TForm1.FormResize(Sender: TObject);
 begin
  Refresh;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
 self.DoubleBuffered:=true;
 //防止圖形閃爍
end;
end.
  保存文件,然后按F9鍵運行程序。在程序運行過程中,會自動在窗體上繪制正弦曲線,運行結(jié)果如圖1所示。

圖1 程序運行結(jié)果

  通過本程序的學習,不但可以繪制正弦曲線,也可以繪制余弦曲線、正切曲線等各式各樣的曲線,方便科學研

 

 

 

基本安裝1、對于單個控件,Componet-->install component..-->PAS或DCU文件-->install;2、對于帶*.dpk文件的控件包,F(xiàn)ile-->Open(下拉列表框中選*.dpk)-->install即可;3、對于帶*.bpl文件的控件包,Install Packages-->Add-->bpl文件名即可;4、如果以上Install按鈕為失效的話,試試Compile按鈕;5、是run time lib則在option下的packages下的runtimepackes加之。    如果編譯時提示文件找不到的話,一般是控件的安裝目錄不在Delphi的Lib目錄中,有兩種方法可以解決:1、反安裝的源文件拷入到Delphi的Lib目錄下;2、或者Tools-->Environment Options中把控件源代碼路徑加入到Delphi的Lib目錄中即可。注意:所安裝的控件是否與你所用的Delphi版本相適應。
 控件刪除在Component/Install Packages中刪除。 選Component/configure Palette…有pages和components兩個區(qū)域雙擊components區(qū)域,選中要刪除得控件,下面有得Delete按鈕但系統(tǒng)提供的控件只能Hide,不能delete。打開控件所在的包文件(*.dpk),從中刪除控件那個文件,再重新編譯該包即可如果是整個控件包都要刪除的話,project->Option->Packages,刪掉那個packages,ok~

 

   ARP -s -d-a
  
   -s——將相應的IP地址與物理地址的捆綁。
  
   -d——刪除所給出的IP地址與物理地址的捆綁。
  
   -a——通過查詢Arp協(xié)議表來顯示IP地址和對應物理地址情況。

 

、怎么樣在delphi中調(diào)動其它*.exe文件?
例如:winexec('d:/鄭洽/Project1.exe',sw_show);

==============================================================================

2、如何讓工程運行時主窗體就是最大化的?
答:設置主窗體的WindowsState屬性為wsMaximized就可以了!
wsNormal 窗體以普通狀態(tài)顯示
wsMinimized 窗體以最小化狀態(tài)顯示。
wsMaximized 窗體以最大化狀態(tài)顯示。

==============================================================================

3、我想先->閃現(xiàn)窗體->主窗體->登錄窗體,工程源文件怎么設置?
答:
⒈開始一個新工程。給表格起名為MainForm,MainForm的單元起名為Main, 工程文 件起名為Test。
⒉在MainForm中插入一個Button部件,將其Caption屬性設為“關閉”,為該部件 的onClick事件創(chuàng)建一個過程,并在過程的begin和end之間插入Close語句。
⒊在應用程序添加一個表格,將這個表格起名為MoveForm,MoveForm 的單元起名 為Move。
⒋為便于演示,在MoveForm中插入一個Label部件,設置其Caption 屬性為“歡迎 進入本系統(tǒng)”。
5.下一步修改工程的源代碼。選擇View/Project Source,修改begin和end之間的 語句如下:
程序清單Test.Dpr
program Test
uses
forms,
Main in 'MAIN.PAS'{MainForm},
Move in 'Move.PAS'{MoveForm}

{$R *.RES}

begin
MoveForm:=TMoveForm.Create(Application);{Create創(chuàng)建閃現(xiàn)窗口對象}
MoveForm.Show;
MoveForm.Update;
Application.CreateForm(TMainForm,MainForm);
MoveForm.Hide;
MoveForm.Free;{Free從內(nèi)存中釋放對象}
Application.Run;
end.
  第一條語句創(chuàng)建了對象,該對象存在內(nèi)存中,但還不能看見, 為了讓它出現(xiàn)并更 新它的內(nèi)容,調(diào)用對象的Show和Update成員函數(shù):Show和Update。 當閃現(xiàn)窗口使 用完后,用Hide函數(shù)將它隱藏起來,然后用Free函數(shù)釋放它所占據(jù)的內(nèi)存。
6.如果此刻你編譯和運行程序,MoveForm窗口一閃而過, 你可能未來得及看 清。為使MoveForm窗口顯示幾秒種,我們可為MainForm的OnCreate 事件創(chuàng)建一個 處理程序,延遲MoveForm窗口的顯現(xiàn)時間。
program TMainForm.FormCreate(sender:Tobject);
var
currentTime:LongInt;
begin
currentTime:=GetTickCount div 1000;
while ((GetTickCount div 1000)<(currentTime+3) do
{不做任何事);
end;
end.
  GetTickCount函數(shù)返回窗口啟動后過去的毫秒數(shù),這個值除以1000 轉(zhuǎn)化為秒數(shù)。 此時你編譯運行程序,就能得到一個延遲3秒多的閃現(xiàn)窗口。
為閃現(xiàn)窗口添加上Image部件,再對字體及窗口進行修飾,我們就能為應用程 序,創(chuàng)建一個精美的封面或在程序啟動時顯示重要提示。

制作登錄窗體一個很方便的方法就是主窗體作為主窗體,登錄成功Hide掉就行了。
如果登錄窗體不可以作為主窗體,那么和閃現(xiàn)窗體一樣的方法創(chuàng)建登錄窗體,加在Application.Run;之前,MoveForm.Free;之后,
用showmodal顯示登錄窗體

==============================================================================

4、button上面的文字怎么樣換行?
答:
button控件不行
bitbtn控件可以。
bitbtn1.caption:='aaaa'#13'bbbbb'

==============================================================================

5、怎么樣判別焦點是否在某個控件上?
答:
if Tobject.focused then
//焦點在某某控件上
else

==============================================================================

6、怎么樣在程序中使一個節(jié)點的子節(jié)點展開及收閉?
答:
treeview1.selected.Expanded; //判斷節(jié)點的子節(jié)點是否展開True展開,否則閉攏
treeview1.selected.Expand(True);//子節(jié)點展開
treeview1.selected.collapse(True)://子節(jié)點閉攏

樹節(jié)點全部展開:
procedure TForm1.Button1Click(Sender: TObject);
var node:TTreeNode;
begin
if treeview1.Items[0]<>nil then
begin
node:=treeview1.Items[0];
node.Expand(true);
while node.getNextSibling<>nil do
begin
node:=node.getNextSibling;
node.Expand(true);
end;
end;
end;

樹節(jié)點全部收縮:
procedure TForm1.Button2Click(Sender: TObject);
var node:TTreeNode;
begin
if treeview1.Items[0]<>nil then
begin
node:=treeview1.Items[0];
node.Collapse(true);
while node.getNextSibling<>nil do
begin
node:=node.getNextSibling;
node.Collapse(true);
end;
end;
end;

==============================================================================

7、如何用delphi編程實現(xiàn)給access數(shù)據(jù)庫加密碼?
答:1,新建Project。
  2,在FORM中放入ADOConnection控件。
  3,雙擊ADOConnection控件,然后點擊Build...按鈕,在“提供者”頁中選擇“Microsoft Jet 4.0 OLE DB   Provider”,然后點擊“下一步”按鈕,在“連接”頁中選擇要連接的Access數(shù)據(jù)庫的路徑和數(shù)據(jù)庫的文件名,這時如果點“測試連接”按鈕時,出現(xiàn)“初始化提供者時發(fā)生錯誤,測試連接失敗,密碼無效”的錯誤提示。
  4,這時點“所有”頁,然后雙擊“Jet OLEDB:Database Password”,出現(xiàn)對話框,添入密碼后,選擇“連接”頁中的“測試連接”按鈕,出現(xiàn)“測試連接成功”的對話框。把ADOConnection控件的LoginPromtp設為false.
  5,設置連接完成。

==============================================================================

8、如何判斷Treeview中我選中的節(jié)點是否有子節(jié)點?如果沒有給出提示啊?
答:
if Treeview.Selected.HasChildren then
//有
else
//無

var
Node :TTreeNode;
begin
Node :=TreeView1.Selected;
if Node.HasChildren then
....
對復雜的程序最好用Node過渡

==============================================================================

9、能否解釋一下try...except...end及try...finally...end;?
1.(1)是用于撲捉異常,(2)是用于保證代碼執(zhí)行的完整性
2.(1)中finally處的代碼不管什么情況都會被執(zhí)行,(2)中except處的代碼僅在發(fā)生異常時才會執(zhí)行
3.try finally之間的代碼雖可保證finally 和 end之間的程序能執(zhí)行,但不能保證程序不崩潰,
而try except就不會使程序崩潰

==============================================================================

10、怎么樣在主程序控制器中加入音樂?
在implementation下加入 mmsystem單元(windows多媒體函數(shù)動態(tài)聯(lián)結(jié)庫)。然後在的onShow,onCreate事件中編寫代碼:sndplaysound('sound.wav',snd_async)

==============================================================================

11、我在form1上有四個edit,輸完后我想用下上箭頭鍵進行上移下移?怎么辦?
答:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=vk_down then perform(WM_NEXTDLGCTL,0,0) else
if key=vk_up then perform(WM_NEXTDLGCTL,1,0);
end;

==============================================================================

12、如何用delphi5實現(xiàn)讀文本文件指定的一行,并得到文本文件的總行數(shù)?謝謝!
答:
Delphi讀文件文件一般使用Readln過程,如要讀第3行可以這樣:
var
i : Integer;
F: TextFile;
S: string;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
Reset(F);
For i = 1 To 3 Do
Readln(F, S);
Edit1.Text := S; { Put string in a TEdit control }
CloseFile(F);
.
end;
要統(tǒng)計總行數(shù),只能從頭逐行讀,直到文件尾(Eof函數(shù)為True),每讀一行計數(shù)器加1。
不過由于文本文件的每行長度不相等,它不能象數(shù)據(jù)庫文件那樣想讀那行就讀哪行,只能順序讀。
上面的方法容易理解,也容易實現(xiàn)。如果希望提高速度,編程上要麻煩一些,可以以二進制方式打開文件,將所有內(nèi)容讀入一個內(nèi)存變量,然后使用Pos函數(shù)查找其中的回車(#13)個數(shù),這樣可以快速地統(tǒng)計總行數(shù)并能快速地找到指定行。

==============================================================================

13、制作主窗口顯示前的版權(quán)窗口
答:
在工程文件中選File->New Form新建一個窗口,設計好窗口的外觀。給窗口起名為AboutBox,選Project->Options,將新建的窗口從自動建立中去掉。選View->Project Source,打開工程文件的源文件,在下面加入紅色的句子。
Uses AboutBox
Var
lTime :TDateTime;
Begin
Application.Initialize();
AboutBox=TAboutBox.Create(AboutBox);
AboutBox.Show;
AboutBox.Update;
lTime=GetTickCount;
Application.CreateForm(TMainForm,MainForm);
while((GetTickCount-lTime) / 1000 <3) do;
AboutBox.Hide;
AboutBox.Free;
Application.Run;
end;

==============================================================================

14、Delphi中RichEdit的奧妙
  一、如何得知當前行號   
  用RichEdit(或者memo)控件制作文本編輯器時,通過訪問lines?count屬性可以得到總行數(shù),但是若想知道光標當前所在行的行號就麻煩了,因為delphi沒有提供這個屬性。要實現(xiàn)這個編輯器必備功能,就須調(diào)用em_ LineFromChar。

  請試試下面的程序。
  先在窗口中布置一個RichEdit或者memo(命名為editor),以及一個button。在button的onclick事件中寫入下列代碼。
   var
   CurrentLine:Integer;
   begin
     CurrentLine:=Editor.Perform(em_ LineFromChar,SFFFF,0);   
     Application.MessageBox(PChar(′當前行號是′+IntToStr(CurrentLine)),′消息′,mb_ iconinformation);   
   end;
  需要注意的是,第一行的行號為零。

  二、如何撤消操作(undo)
  對于memo來說,實現(xiàn)undo是不需編程的,只要讓popupmenu屬性為空,運行時就能用鼠標右鍵激活一個常用操作菜單,其中包括撤消、剪切、復制、粘貼、刪除和全選六項?! 〉上У氖?,這一招對于功能強大的RichEdit控件居然行不通,害得我們還要自己設計一個popupmemu。當你用 CutToClipBoard等語句輕松而順利地完成了“剪切”等功能,接著便會無奈地發(fā)現(xiàn),竟找不到undo或cancel之類的語句來執(zhí)行“撤消”。  這時你需要這樣處理:
    RichEdit1?Perform(EM_UNDO,0,0);
  另外還應檢查是否允許撤消,從而開啟或關閉彈出菜單中的“撤消”項:
    Undo1?Enabled:=RichEdit?
    Perform(EM_CANUNDO,0,0)<>0;   
以上程序在Delphi3中調(diào)試通過?! ?/p>

==============================================================================

15、在主窗口中打開另一個獨立的窗口,而這個被打開的窗口固定顯示在..?
答:
procedure TForm2.FormCreate(Sender: TObject);
begin
form2.Hide;
self.Parent:=form1.Panel1;
end;

==============================================================================

16、SaveDialog1確認文件存不存在的辦法?
答:
procedure TForm1.SaveDialog1CanClose(Sender: TObject;
var CanClose: Boolean);
begin
if FileExists(SaveDialog1.FileName) then //如果文件已經(jīng)存在
if MessageDlg('文件已經(jīng)存在,保存嗎?', mtConfirmation, [mbYes, mbNo], 0) <> mrYes then
Button2.Click ; //如果選擇了覆蓋,則退出,否則,重新讓用戶選擇文件
end;

==============================================================================

17、正確關閉一個MDI子窗口?
答:
Delphi中MDI子窗口的關閉方式默認為縮小而不是關閉,所以當你單擊子窗口右上角的關閉按鈕時會發(fā)覺該子窗口只是最小化,而不是你預期的那樣被關閉。解決辦法是在子窗口的OnClose事件處理過程中加入如下代碼,示例:

procedure ChildForm.OnClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;

  Delphi為一個Form的關閉行為指定了四種方式,分別是:

caNone 禁止Form被關閉
caHide Form不被關閉,但是被隱藏。被隱藏的Form仍然可以被程序訪問。
caFree Form被關閉,并且釋放其占用的資源。
caMinimize Form被最小化而不是被關閉,這是MDI子窗口的默認關閉行為。

==============================================================================

18、怎樣記MDI子窗口不在母體運行時就被打開?
答:
在project下的options中forms里面除了form1外,其余的移到右邊的框里,然后在調(diào)用顯示的按鈕下編寫語句,以form2調(diào)用為例:
form2:=Tform2.create(self);
form2.show;

==============================================================================

19、限制FORM的大小
答:
在FORM私有聲明部分加上如下一行:

procedure WMGetMinMaxInfo( var Message:TWMGetMinMaxInfo );message WM_GETMINMAXINFO;
在聲明部分加上如下幾行:
procedure TForm1.WMGetMinMaxInfo( var Message :TWMGetMinMaxInfo );
begin
with Message.MinMaxInfo^ do
begin
ptMaxSize.X := 200; {最大化時寬度}
ptMaxSize.Y := 200; {最大化時高度}
ptMaxPosition.X := 99; {最大化時左上角橫坐標}
ptMaxPosition.Y := 99; {最大化時左上角縱坐標}
end;
Message.Result := 0; {告訴Windows你改變了 minmaxinfo}
inherited;
end;

==============================================================================

20、隨機數(shù)生成法
答:
Randomize;
rn:=inttostr(random(9999));
rn1:=inttostr(random(9999));
.....

==============================================================================

21、怎樣把程序隱藏起來,在WINDOWS界面上沒有顯示??
答:
在application.run之前加入application.showmain:=false!

==============================================================================

22、怎樣將一個form1.free的form1窗體重新顯示?
答:
form2:=TForm2.Create(application);
form2.Show;

如果你要創(chuàng)建的Form2窗體能嵌入一個Panel中,指定Parent:
form2:=TForm2.Create(application);
form2.Parent:=panel1;
form2.Show;

==============================================================================

23、我想在bitbtn上設快捷按鈕Esc,怎么辦?
答:
procedure TForm1.BitBtn1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=27 then
application.Terminate;
end;

設它的cancel屬性為true就行了~~

==============================================================================

24、什么叫做托盤區(qū)?
答:
托盤區(qū)就是在windows的狀態(tài)欄下方顯示時鐘、輸入法狀態(tài)的地方,

要把你的程序顯示在托盤區(qū):
下面是一個托盤類,只要把下面粘貼到文本文件中,改成TrayIcon.pas,使用時uses TrayIcon就可以了。

先聲明一個全局變量:
var tray:TTrayNotifyIcon;

然后在窗體的OnCreate事件中:
tray:=TTrayNotifyIcon.Create(self);//將窗體創(chuàng)建為托盤
tray.Icon:=application.Icon;//定義托盤的顯示圖標
tray.IconVisible:=true;//托盤可見
tray.PopupMenu:=popmenu;//給托盤定義一個右擊時的彈出菜單
tray.OnDblClick:=trayDblClick;//給托盤定義一個雙擊事件(當然要自己寫了,不過多數(shù)情況只有一行,就是Form1.show);

unit TrayIcon;

interface

uses Windows, SysUtils, Messages, ShellAPI, Classes, Graphics, Forms, Menus,
StdCtrls, ExtCtrls;

type
ENotifyIconError = class(Exception);

TTrayNotifyIcon = class(TComponent)
private
FDefaultIcon: THandle;
FIcon: TIcon;
FHideTask: Boolean;
FHint: string;
FIconVisible: Boolean;
FPopupMenu: TPopupMenu;
FonClick: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FNoShowClick: Boolean;
FTimer: TTimer;
Tnd: TNotifyIconData;
procedure SetIcon(Value: TIcon);
procedure SetHideTask(Value: Boolean);
procedure SetHint(Value: string);
procedure SetIconVisible(Value: Boolean);
procedure SetPopupMenu(Value: TPopupMenu);
procedure SendTrayMessage(Msg: DWORD; Flags: UINT);
function ActiveIconHandle: THandle;
procedure OnButtonTimer(Sender: TObject);
protected
procedure Loaded; override;
procedure LoadDefaultIcon; virtual;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Icon: TIcon read FIcon write SetIcon;
property HideTask: Boolean read FHideTask write SetHideTask default False;
property Hint: String read FHint write SetHint;
property IconVisible: Boolean read FIconVisible write SetIconVisible default False;
property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;
property onClick: TNotifyEvent read FonClick write FonClick;
property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
end;

implementation

{ TIconManager }
{ This class creates a hidden window which handles and routes }
{ tray icon messages }
type
TIconManager = class
private
FHWindow: HWnd;
procedure TrayWndProc(var Message: TMessage);
public
constructor Create;
destructor Destroy; override;
property HWindow: HWnd read FHWindow write FHWindow;
end;

var
IconMgr: TIconManager;
DDGM_TRAYICON: Cardinal;

constructor TIconManager.Create;
begin
FHWindow := AllocateHWnd(TrayWndProc);
end;

destructor TIconManager.Destroy;
begin
if FHWindow <> 0 then DeallocateHWnd(FHWindow);
inherited Destroy;
end;

procedure TIconManager.TrayWndProc(var Message: TMessage);
{ This allows us to handle all tray callback messages }
{ from within the context of the component. }
var
Pt: TPoint;
TheIcon: TTrayNotifyIcon;
begin
with Message do
begin
{ if it’s the tray callback message }
if (Msg = DDGM_TRAYICON) then
begin
TheIcon := TTrayNotifyIcon(WParam);
case lParam of
{ enable timer on first mouse down. }
{ onClick will be fired by OnTimer method, provided }
{ double click has not occurred. }
WM_LBUTTONDOWN: TheIcon.FTimer.Enabled := True;
{ Set no click flag on double click. This will supress }
{ the single click. }
WM_LBUTTONDBLCLK:
begin
TheIcon.FNoShowClick := True;
if Assigned(TheIcon.FOnDblClick) then TheIcon.FOnDblClick(Self);
end;
WM_RBUTTONDOWN:
begin
if Assigned(TheIcon.FPopupMenu) then
begin
{ Call to SetForegroundWindow is required by API }
SetForegroundWindow(IconMgr.HWindow);
{ Popup local menu at the cursor position. }
GetCursorPos(Pt);
TheIcon.FPopupMenu.Popup(Pt.X, Pt.Y);
{ Message post required by API to force task switch }
PostMessage(IconMgr.HWindow, WM_USER, 0, 0);
end;
end;
end;
end
else
{ If it isn’t a tray callback message, then call DefWindowProc }
Result := DefWindowProc(FHWindow, Msg, wParam, lParam);
end;
end;

{ TTrayNotifyIcon }

constructor TTrayNotifyIcon.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FIcon := TIcon.Create;
FTimer := TTimer.Create(Self);
with FTimer do
begin
Enabled := False;
Interval := GetDoubleClickTime;
OnTimer := OnButtonTimer;
end;
{ Keep default windows icon handy... }
LoadDefaultIcon;
end;

destructor TTrayNotifyIcon.Destroy;
begin
if FIconVisible then SetIconVisible(False); // destroy icon
FIcon.Free; // free stuff
FTimer.Free;
inherited Destroy;
end;

function TTrayNotifyIcon.ActiveIconHandle: THandle;
{ Returns handle of active icon }
begin
{ If no icon is loaded, then return default icon }
if (FIcon.Handle <> 0) then
Result := FIcon.Handle
else
Result := FDefaultIcon;
end;

procedure TTrayNotifyIcon.LoadDefaultIcon;
{ Loads default window icon to keep it handy. }
{ This will allow the component to use the windows logo }
{ icon as the default when no icon is selected in the }
{ Icon property. }
begin
FDefaultIcon := LoadIcon(0, IDI_WINLOGO);
end;

procedure TTrayNotifyIcon.Loaded;
{ Called after component is loaded from stream }
begin
inherited Loaded;
{ if icon is supposed to be visible, create it. }
if FIconVisible then
SendTrayMessage(NIM_ADD, NIF_MESSAGE or NIF_ICON or NIF_TIP);
end;

procedure TTrayNotifyIcon.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = PopupMenu) then
PopupMenu := nil;
end;

procedure TTrayNotifyIcon.OnButtonTimer(Sender: TObject);
{ Timer used to keep track of time between two clicks of a }
{ double click. This delays the first click long enough to }
{ ensure that a double click hasn’t occurred. The whole }
{ point of these gymnastics is to allow the component to }
{ receive onClicks and OnDblClicks independently. }
begin
{ Disable timer because we only want it to fire once. }
FTimer.Enabled := False;
{ if double click has not occurred, then fire single click. }
if (not FNoShowClick) and Assigned(FonClick) then
FonClick(Self);
FNoShowClick := False; // reset flag
end;

procedure TTrayNotifyIcon.SendTrayMessage(Msg: DWORD; Flags: UINT);
{ This method wraps up the call to the API’s Shell_NotifyIcon }
begin
{ Fill up record with appropriate values }
with Tnd do
begin
cbSize := SizeOf(Tnd);
StrPLCopy(szTip, PChar(FHint), SizeOf(szTip));
uFlags := Flags;
uID := UINT(Self);
Wnd := IconMgr.HWindow;
uCallbackMessage := DDGM_TRAYICON;
hIcon := ActiveIconHandle;
end;
Shell_NotifyIcon(Msg, @Tnd);
end;

procedure TTrayNotifyIcon.SetHideTask(Value: Boolean);
{ Write method for HideTask property }
const
{ Flags to show application normally or hide it }
ShowArray: array[Boolean] of integer = (sw_ShowNormal, sw_Hide);
begin
if FHideTask <> Value then
begin
FHideTask := Value;
{ Don’t do anything in design mode }
if not (csDesigning in ComponentState) then
ShowWindow(Application.Handle, ShowArray[FHideTask]);
end;
end;

procedure TTrayNotifyIcon.SetHint(Value: string);
{ Set method for Hint property }
begin
if FHint <> Value then
begin
FHint := Value;
if FIconVisible then
{ Change hint on icon on tray notification area }
SendTrayMessage(NIM_MODIFY, NIF_TIP);
end;
end;

procedure TTrayNotifyIcon.SetIcon(Value: TIcon);
{ Write method for Icon property. }
begin
FIcon.Assign(Value); // set new icon
{ Change icon on notification tray }
if FIconVisible then SendTrayMessage(NIM_MODIFY, NIF_ICON);
end;

procedure TTrayNotifyIcon.SetIconVisible(Value: Boolean);
{ Write method for IconVisible property }
const
{ Flags to add or delete a tray notification icon }
MsgArray: array[Boolean] of DWORD = (NIM_DELETE, NIM_ADD);
begin
if FIconVisible <> Value then
begin
FIconVisible := Value;
{ Set icon as appropriate }
SendTrayMessage(MsgArray[Value], NIF_MESSAGE or NIF_ICON or NIF_TIP);
end;
end;

procedure TTrayNotifyIcon.SetPopupMenu(Value: TPopupMenu);
{ Write method for PopupMenu property }
begin
FPopupMenu := Value;
if Value <> nil then Value.FreeNotification(Self);
end;

const
{ String to identify registered window message }
TrayMsgStr = ’DDG.TrayNotifyIconMsg’;

initialization
{ Get a unique windows message ID for tray callback }
DDGM_TRAYICON := RegisterWindowMessage(TrayMsgStr);
IconMgr := TIconManager.Create;
finalization
IconMgr.Free;
end.

==============================================================================

25、關于窗體釋放的問題(formX.free)?
答:
這個我知道,模式窗口用:form2 := TForm2.Create(Application);
try
if form2.showModal = mrOK then
{do Something}
finally
form2.free;
form2 := nil;
end; 非模式窗口用:if not Assigned(form2) then
form2 := Tfrom2.Create(Application);
form2.show;

//然后在form2的Close事件中加入以下句
Action := caFree;

//在from2的Destory事件中加入以下句
form2 := nil; 搞定!!!

==============================================================================

26、關于MDI窗體的問題?
答:
我不知道是如何實現(xiàn),但我知道一個方法可以實現(xiàn)同樣的功能,在打開子窗體前加一句
button1.SendToBack;

==============================================================================

27、小數(shù)點'.'的鍵號是什么?回車是#13,'.'是什么?
答:
你可以用此得出所有鍵的值procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
label1.caption:=IntToStr(key);
end;

==============================================================================
==============================================================================

1、判斷機器是否網(wǎng)絡狀態(tài)
答:
uses WinInet;
procedure TForm1.Button1Click(Sender: TObject);
function GetOnlineStatus : Boolean;
var ConTypes : Integer;
begin
ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY;
if (InternetGetConnectedState(@ConTypes, 0) = False)
then Result := False
else Result := True;
end;
begin
if not GetOnlineStatus then ShowMessage('Not Connected');
end;

==============================================================================

2、[DELPHI]窗體漸漸出現(xiàn)
答:
AnimateWindow(Handle,1000,AW_CENTER);
//在窗體創(chuàng)建事件中

==============================================================================

3、如何取得一臺機器的CPU占用率???
答:
使用下面的方法
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

const
SystemBasicInformation = 0;
SystemPerformanceInformation = 2;
SystemTimeInformation = 3;

type
TPDWord = ^DWORD;

TSystem_Basic_Information = packed record
dwUnknown1: DWORD;
uKeMaximumIncrement: ULONG;
uPageSize: ULONG;
uMmNumberOfPhysicalPages: ULONG;
uMmLowestPhysicalPage: ULONG;
uMmHighestPhysicalPage: ULONG;
uAllocationGranularity: ULONG;
pLowestUserAddress: Pointer;
pMmHighestUserAddress: Pointer;
uKeActiveProcessors: ULONG;
bKeNumberProcessors: byte;
bUnknown2: byte;
wUnknown3: word;
end;

type
TSystem_Performance_Information = packed record
liIdleTime: LARGE_INTEGER; {LARGE_INTEGER}
dwSpare: array[0..75] of DWORD;
end;

type
TSystem_Time_Information = packed record
liKeBootTime: LARGE_INTEGER;
liKeSystemTime: LARGE_INTEGER;
liExpTimeZoneBias: LARGE_INTEGER;
uCurrentTimeZoneId: ULONG;
dwReserved: DWORD;
end;

var
NtQuerySystemInformation: function(infoClass: DWORD;
buffer: Pointer;
bufSize: DWORD;
returnSize: TPDword): DWORD; stdcall = nil;

liOldIdleTime: LARGE_INTEGER = ();
liOldSystemTime: LARGE_INTEGER = ();
SysBaseInfo: TSystem_Basic_Information;
SysPerfInfo: TSystem_Performance_Information;
SysTimeInfo: TSystem_Time_Information;
status: Longint; {long}
dbSystemTime: Double;
dbIdleTime: Double;
function GetCPUUsage:Double;
implementation
function Li2Double(x: LARGE_INTEGER): Double;
begin
Result := x.HighPart * 4.294967296E9 + x.LowPart
end;

function GetCPUUsage:Double;
var
bLoopAborted : boolean;
begin
if @NtQuerySystemInformation = nil then
NtQuerySystemInformation := GetProcAddress(GetModuleHandle(‘ntdll.dll‘),
‘NtQuerySystemInformation‘);
// get number of processors in the system
status := NtQuerySystemInformation(SystemBasicInformation, @SysBaseInfo, SizeOf(SysBaseInfo), nil);
if status <> 0 then Exit;
// Show some information
{with SysBaseInfo do
begin
ShowMessage(
Format(‘uKeMaximumIncrement: %d‘#13‘uPageSize: %d‘#13+
‘uMmNumberOfPhysicalPages: %d‘+#13+‘uMmLowestPhysicalPage: %d‘+#13+
‘uMmHighestPhysicalPage: %d‘+#13+‘uAllocationGranularity: %d‘#13+
‘uKeActiveProcessors: %d‘#13‘bKeNumberProcessors: %d‘,
[uKeMaximumIncrement, uPageSize, uMmNumberOfPhysicalPages,
uMmLowestPhysicalPage, uMmHighestPhysicalPage, uAllocationGranularity,
uKeActiveProcessors, bKeNumberProcessors]));
end;
}
bLoopAborted := False;
while not bLoopAborted do
begin
// get new system time
status := NtQuerySystemInformation(SystemTimeInformation, @SysTimeInfo, SizeOf(SysTimeInfo), 0);
if status <> 0 then Exit;
// get new CPU‘s idle time
status := NtQuerySystemInformation(SystemPerformanceInformation, @SysPerfInfo, SizeOf(SysPerfInfo), nil);
if status <> 0 then Exit;
// if it‘s a first call - skip it
if (liOldIdleTime.QuadPart <> 0) then
begin
// CurrentValue = NewValue - OldValue
dbIdleTime := Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
dbSystemTime := Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
// CurrentCpuIdle = IdleTime / SystemTime
dbIdleTime := dbIdleTime / dbSystemTime;
// CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
dbIdleTime := 100.0 - dbIdleTime * 100.0 / SysBaseInfo.bKeNumberProcessors + 0.5;
// Show Percentage
//Form1.Label1.Caption := FormatFloat(‘CPU Usage: 0.0 %‘,dbIdleTime);
//Application.ProcessMessage

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多