線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2478
推到 Plurk!
推到 Facebook!

由 Delphi 進入 C#

 
digitraveler
初階會員


發表:89
回覆:91
積分:46
註冊:2005-06-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-06-07 12:01:26 IP:211.21.xxx.xxx 訂閱
小弟剛接觸 C# , 希望趕快上手 , 但由於對語法的不熟悉不習慣 , 處處遇到瓶頸 , 好在遇到版內幾位大大的幫忙 , 自己再整理測試 , 包裝了一個 Delphi Like 的副函式 , 藉此拋磚引玉 , 希望大家幫忙增加這個 Delphi Like 副函式的內容 , 目前這個 副函式 提供 
1.類 Delphi 的副函式
2.ini 檔的讀寫
3.公用變數

有了以上功能,要讓 C#新手開發一個商業程式,已經具有七八成的資源了,可以省下C#新手 ERROR & TRY 的時間
<textarea class="c#" rows="10" cols="60" name="code">using System; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Text; using System.IO; namespace DelphiLike { //------------------------------------------------- //MyFunction //------------------------------------------------- class My { public static void ShowMessage(string bufstr) { MessageBox.Show(bufstr); } public static string ApplicationName() { return System.Windows.Forms.Application.ExecutablePath; } public static string ApplicationIniName() { string tmp; tmp=System.Windows.Forms.Application.ExecutablePath; tmp=tmp.Substring(0,tmp.Length-4) ".ini"; return tmp; } public static string IntToStr(int v) { return v.ToString(); } public static int StrToInt(string bufstr) { return 0; } public static string Trim(string bufstr) { return bufstr.Trim(); } public static int Length(string bufstr) { return bufstr.Length; } public static string Copy(string bufstr, int stridx, int len) { return bufstr.Substring(stridx-1,len); } public static string Left(string bufstr, int len) { return bufstr.Substring(0,len); } public static string Right(string bufstr, int len) { if (bufstr.Length
使用方法
1.在主 Form (Form1.cs) 中 usign DelphiLike

2.使用 DelphiLike 函式
(a).要秀變數內容
string a="test";
My.ShowMessage(a);
(b)取得執行檔路徑
string apexe=My.ApplicationName();
(c)將整數轉字串
int i=10;
string tmp=My.IntToStr(i);

3.使用 INI (不用宣告,不用 CREATE , 不用 FREE)
將變數值取出
string tmp=MyIni.ReadString("section1","key1","default str");
寫入變數到 ini
MyIni.WriteString("section1","key1",tmp);

4.使用 global 變數
只要 Form1,Form2,Form3......皆有宣告 usign DelphiLike
他們讀寫的 g.test 變數都是同一個 (g 類別下還有哪些 global , 自己在DelphiLike 的 g 類別內自行定義即可 )


以上接經過測試 , 若有謬誤疏漏還望指正 , 若有更精簡的方法還望指導
3Q3Q








系統時間:2024-05-02 0:54:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!