廣告

2024 年 3 月
 123
45678910
11121314151617
18192021222324
25262728293031

彙整

DELPHI 寫入讀取INI範例

程式範例

uses      inifiles;

procedure TForm1.btn3Click(Sender: TObject); var   inifile: TInifile;   iniFileName,sAppPath,sMusicDir,sImageDir:string; begin   […]

DELPHI使用lkJSON多層次一般取值與陣列取值範例

文章出處 http://rakelitica.blogspot.com/2012/07/using-lkjson-example-with-google-drive.html

JSON文件範本(可貼到 https://jsoneditoronline.org/#left=local.lapedo&right=local.vaxeha 幫你線上格式化JSON比較好看懂)

{   "kind": "drive#fileList",   "etag": "\"ia2FS23424234234ANFYAdsc1Tyua2KKA-HnMs\"",   "selfLink": "https://www.googleapis.com/drive/v2/files",   "items": [   {    "kind": "drive#file", […]

呼叫外部程式達成SFTP連線

出處https://dotblogs.com.tw/jean/2013/11/06/126876

有些早期舊程式語言並沒有支援SFTP元件,可透過呼叫外部程式來達成

SFTP使用WinSCP

SFTP使用WinSCP

WinSCP目前是免費的FTP軟體

1. 到WinSCP網站下載WinSCP.exe

http://winscp.net/eng/download.php

2.產生Ftp.bat檔,檔案內容如下:

winscp.exe /console /script="C:\winscp\winscp-script.txt"

3.產生winscp-script.txt檔,檔案內容如下:

option batch abort option confirm off option transfer binary open sftp://LoginID:LogPwd@FTP_Host -hostkey="ssh-rsa 1024  XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:X:XX:XX:XX:XX" put d:\examplefile.txt close exit

說明:open […]

[Delphi 7](2014.3.3改)Indy 10 網路元件安裝-複製文章保留用

感謝作者 出處:http://idlemanhome.blogspot.com/2013/12/delphi-7indy-10.html

Delphi 7](2014.3.3改)Indy 10 網路元件安裝

舊的方法原本是以下這樣,後來我裝新的XP系統時發現無法成功

首先從 http://www.indyproject.org/downloads/10/indy10.0.52_source.zip 下載壓縮檔。 (或是到這個網頁找 http://www.indyproject.org/sockets/download/files/indy10.en.aspx )

Indy 10 安裝步驟:
移除舊版 Indy 9

進 Delphi 後,選擇 Component –> Install Packages…
在 Design Packages 找有 Indy 字樣的選項後,Remove 後離開。
在 Delphi 裡,選擇 Tools –> Environment Options,打開 Library 標籤,刪除有Indy 的路徑。
在系統資料夾找所有 Indy 開頭的 Indy*.bpl 和 Indy*.dcp 檔案,並刪除。

開始安裝:

解壓縮剛下載的 Indy10.0.52_source.zip 檔至 您放置 […]

使用 DELPHI 抓取 WINDOWS 內的環境變數值

使用 DELPHI 抓取 WINDOWS 內的環境變數值

GetEnvironmentVariable(‘TEMP’)

其中TEMP為WINDOWS的環境變數

Windows 在 command 模式下輸入 set 也可秀出現有 Windows 的環境變數,把變數值帶入這個 Function 內即可取得,回傳值是文字型態。

Windows常用變數: 參考來源:http://jck11.pixnet.net/blog/post/13459124-windows%E7%B3%BB%E7%B5%B1%E5%85%A7%E5%BB%BA%E7%9A%84%E5%B8%B8%E8%A6%8B%E7%92%B0%E5%A2%83%E8%AE%8A%E6%95%B8

%ALLUSERSPROFILE%:All Users設定檔的資料夾位置。 %APPDATA%:目前使用者的Application Data資料夾位置。 %CD%:目前的工作資料夾。 %CLIENTNAME%:目前使用者的NETBIOS電腦名稱。 %CMDCMDLINE%:處理目前命令提示字元視窗命令的cmd.exe的完整路徑。 %CMDEXTVERSION%:目前Command Processor Extensions的版本。 %COMPUTERNAME%:電腦名稱。 %COMSPEC%::命令提示字元視窗的解譯程式路徑,通常與%CMDCMDLINE%相同。 %CommonProgramFiles%:Common Files資料夾的路徑。 […]

DELPHI 7 下 TEXT檔 ANSI與UTF8互轉方式-Write & Read UTF-8 Text File

DELPHI 7 下 TEXT檔 ANSI與UTF8互轉方式

出處:http://tw.myblog.yahoo.com/cschen99ws/article?mid=16596&prev=18175&l=f&fid=52

procedure TForm1.Button1Click(Sender: TObject); var  S:string;   begin     with   TMemoryStream.Create   do   try             S   :=   #$EF#$BB#$BF;             Write(S[1],   Length(S));             S   :=   AnsiToUtf8(Memo1.Text);             Write(S[1],   Length(S));             Position   :=   0;           SaveToFile(‘c:\temp.txt’);       finally             Free;         end;   end;      procedure TForm1.Button2Click(Sender: TObject); var         […]

Delphi 2010自帶TIdFTP的中文問題

DELPHI7 + INDY

抓檔前先轉UTF8Encode filename:= UTF8Encode(filename);   FIdFtp.Get(filename,tStream,true);

未測試………………

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

出處:http://hi.baidu.com/syncgrey/blog/item/8c894e823c7f78aa6c8119f1.html

1、Delphi 2010自帶TIdFTP的中文問題   最近使用TIdTFP,使用ChangeDir切換到中文目錄時報錯,錯誤提示中的中文目錄成了一串“?”號,閱讀源代碼得知,該控件的默認IOHandle的默認Encoding是ASCII(代碼頁為20127),ITdFTP在Connect方法中,連接成功後,有這麼一句:

    // RLebeau: must not send/receive UTF-8 before negotiating for it…     IOHandler.DefStringEncoding := Indy8BitEncoding;

再轉到Indy8BitEncoding 中看看:

function Indy8BitEncoding(const AOwnedByIndy: Boolean = True): TIdTextEncoding; var   LEncoding: TIdTextEncoding; […]

[DELPHI] cxGrid的使用方法

朋友貼給我的,只知道是大陸網站上分享的資料,可在cxGrid內使用CheckBox喔!!!只是用了之後以前可使用 Shift 選區段的功能似乎不能用了。

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

cxGrid的使用方法

cxGrid功能強大,適合做企業級的複雜查詢。非常方便。

但是對其用法介紹的並不多,在此總結他人的使用經驗和自己的一點小經驗,供大家參考。

(1)動態設置顯示格式

procedure SetDisplayFormat(ACtrlData: TClientDataSet;

  TbView: TcxGridDBTableView);

var

  i: integer;

begin

  if ACtrlData.RecordCount <= 0 then Exit;

  try

    TbView.ClearItems;

    ACtrlData.First;

    for i := 0 to ACtrlData.RecordCount – 1 do

    begin

      if ACtrlData.FieldByName(‘SQBF_DisplayInGrid’).AsString = ‘1’ then //在表格中顯示

      with TbView.CreateColumn do

      begin

        DataBinding.FieldName := ACtrlData.FieldByName(‘SQBF_FieldName’).AsString;

        Caption := ACtrlData.FieldByName(‘SQBF_Caption’).AsString; //欄位中文標題

        Hint := ACtrlData.FieldByName(‘SQBF_Hint’).AsString;

        Width := ACtrlData.FieldByName(‘SQBF_Width’).AsInteger;

        HeaderAlignmentHorz := taCenter;

      end;

      […]

Delphi 下讓使用者選擇目錄方式:

Delphi 下讓使用者選擇目錄方式:

OpenDialog 元件是讓使用者選檔案,那選目錄要使用什麼方式呢?

USE QDialogs

procedure TForm1.cxButton1Click(Sender: TObject); var   Dir: WideString; begin   if SelectDirectory(‘請選擇目錄’, ”, Dir) then   begin     ShowMessage(Dir);   end; end;

SelectDirectory(‘請選擇目錄’, ”, Dir)

第一個參數為提示文字,第二個參數可設定預設目錄,第三個參數為使用者選取目錄後的目錄路徑

可對SelectDirectory按F1查詢使用方式,還有VCL的用法可用,代的參數又不一樣,有興趣的可研究一下。

DELPHI 7 使用ADO元件寫入資料庫強制四捨五入小數到第四位問題

DELPHI 7 使用ADO元件寫入資料庫強制四捨五入小數到第四位問題

parameters.parambyname(‘tmpprice’).datatype:=ftFloat;   <==寫入資料前先將欄位設定成 Float 型態即可解決此問題。

參考:http://jzinfo.javaeye.com/blog/432853

var  
    adoquery1:Tadoquery;  
begin  
    adoquery1:=Tadoquery.create(nil);  
    try  
       if not DM.adonconnection1.connected then  
           DM.adoconnection1.connected:=true;  
       adoquery1.connection:=DM.adoconnection1;  
       adoquery1.enableBCD:=False;       //禁用bcd类型  
       with adoquery1 do  
       begin  
           close;  
           sql.clear;  
           sql.add(‘insert into materialInfo values(:tmppno,:tmpvendor,:tmpdesc,:tmpprice)’);  
           parameters.parambyname(‘tmppno’).value:=trim(edit1.text);  
           parameters.parambyname(‘tmpvendor’).value:=trim(edit2.text);  
           parameters.parambyname(‘tmpdesc’).value:=trim(edit3.text);  
           parameters.parambyname(‘tmpprice’).datatype:=ftFloat;       //设置下数据类型  
           parameters.parambyname(‘tmpprice’).value:=trim(edit4.text);  
           execsql;  
       end;   […]