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

關於用TIniFile紀錄panel的問題..

尚未結案
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-25 20:23:29 IP:61.219.xxx.xxx 未訂閱
之前小弟用TIniFile紀錄Image的問題.. 已經解決了. 後來想進階套用在稍微複雜點的程式裡,結果"沒啥動靜". 也就是說,有做到紀錄的動作了,但是讀取的部分卻沒辦法! 所以想問各位,這是什麼情形! .h
//---------------------------------------------------------------------------    #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include <Forms.hpp>
#include 
#include 
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
        TButton *Button1;
        TButton *Button2;
        TButton *Button3;
        TButton *Button4;
        TImage *Image1;
        TButton *Button5;
        TButton *Button6;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall Image1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
        void __fastcall Image1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
        void __fastcall Image1MouseMove(TObject *Sender, TShiftState Shift,
          int X, int Y);
        void __fastcall FormDestroy(TObject *Sender);
        void __fastcall Button2Click(TObject *Sender);
        void __fastcall Button4Click(TObject *Sender);
        void __fastcall Button5Click(TObject *Sender);
        void __fastcall Button6Click(TObject *Sender);
private:        // User declarations
        int oldX,oldY;
        int Left;
        int Top;
        TPanel *panel;
public:                // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
.cpp
//---------------------------------------------------------------------------    #include 
#include     #pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
bool Moving=false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
     //給於Image1建立一個可拖曳的新平台
     panel = new TPanel(this);
     panel->Parent = Form1;
     //panel邊框加強
     panel->BevelInner = bvLowered;
     panel->BevelOuter = bvLowered;
     //將新增的panel先隱藏起來
     panel->Hide();         Left = panel->Left;//記住起始位置
     Top = panel->Top;
    //將讀取INI的動作寫到Form起始時即可再執行時,直接載入上一次修改的內容
    //PS.前提是該INI檔存在,可以用
    TIniFile *MyIni;
    MyIni=new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));
    //Edit1->Text = MyIni->ReadString("Setting","StringA",0);
    Image1->Left=MyIni->ReadInteger("PC","Left",0);
    Image1->Top=MyIni->ReadInteger("PC","Top",0);
    Image1->Width=MyIni->ReadInteger("PC","Width",0);
    Image1->Height=MyIni->ReadInteger("PC","Height",0);
    delete MyIni;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
     //命名"新增的電腦名稱"(PCName)
     AnsiString PCName;
     PCName=InputBox("新增","輸入電腦名稱    ","");
     //將TImage改命名為PC_Image
     TImage *PC_Image = new TImage(Form1);
     PC_Image->Parent = Form1;
     PC_Image->Name=PCName;
     //新增的Image1以X,Y座標作為落點位置(預設值都為1)
     PC_Image->Left = StrToInt(InputBox("X","輸入電腦image X座標    ","1"));
     PC_Image->Top = StrToInt(InputBox("Y","輸入電腦image Y座標    ","1"));
     //自動找尋AddPc.bmp所在之路徑位置
     AnsiString AppPath  = ExtractFilePath(Application->ExeName);
     PC_Image->Picture->LoadFromFile(AppPath "AddPc.bmp");
     PC_Image->Width = 32;
     PC_Image->Height = 32;
     PC_Image->Stretch = true;
     PC_Image->OnMouseUp = &Image1MouseUp;
     PC_Image->OnMouseDown = &Image1MouseDown;
     PC_Image->OnMouseMove = &Image1MouseMove;         TLabel *PC_Label = new TLabel(Form1);
     PC_Label->Parent = Form1;
     PC_Label->Name=PCName "Label";
     PC_Label->Left = PC_Image->Left;
     PC_Label->Top = PC_Image->Top PC_Image->Height;
     PC_Label->Caption = PCName;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
     //顯示出panel
     panel->Show();
     oldX = X;
     oldY = Y;
     //設定panel顯現狀態
     panel->Left = ((TImage*)Sender)->Left-2;
     panel->Top = ((TImage*)Sender)->Top-2;
     panel->Height = ((TImage*)Sender)->Height 15;
     panel->Width = ((TImage*)Sender)->Width 4;
     panel->Visible = true;         //當滑鼠左鍵按住Image1時,實際上是按住了panel
     ::SetCapture(panel->Handle);
     ((TImage*)Sender)->Parent = panel;
     ((TImage*)Sender)->Left = 2;
     ((TImage*)Sender)->Top = 2;
     //除了ImageL外,Label也一起顯示在新增的panel中
     TLabel *tmpLabel = ((TLabel*)FindComponent(((TImage*)Sender)->Name "Label"));
     tmpLabel->Parent=panel;
     tmpLabel->Left = 2;
     tmpLabel->Top = 2 ((TImage*)Sender)->Height;         Moving=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
     if (Moving)
     {
         Moving=false;
         //釋放panel的滑鼠捕捉
         ::ReleaseCapture();
         //隱藏panel在Image1下
         panel->Visible = false;
         ((TImage*)Sender)->Left = panel->Left;
         ((TImage*)Sender)->Top = panel->Top;
         ((TImage*)Sender)->Parent = this;
         TLabel *tmpLabel = ((TLabel*)FindComponent(((TImage*)Sender)->Name "Label"));
         tmpLabel->Parent=this;
         tmpLabel->Left = panel->Left;
         tmpLabel->Top = panel->Top ((TImage*)Sender)->Height;
     }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
     ////當滑鼠左鍵按住Image1在移動時,實際上是按住了panel在移動
     if (Shift.Contains(ssLeft))
     {
          panel->Left = panel->Left   (X - oldX);
          panel->Top = panel->Top   (Y - oldY);
     }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
     delete panel;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
     //panel->Visible();    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
TIniFile *MyIni;
MyIni=new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));    MyIni->WriteInteger("PC","Left",panel->Left);
MyIni->WriteInteger("PC","Top",panel->Top);
MyIni->WriteInteger("PC","Width",panel->Width);
MyIni->WriteInteger("PC","Height",panel->Height);
MyIni->WriteInteger("PC","OffsetX",Left-panel->Left);
MyIni->WriteInteger("PC","OffsetY",Top-panel->Top);
MyIni->WriteInteger("PC","OldLeft",Left);
MyIni->WriteInteger("PC","OldTop",Top);
delete MyIni;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
TIniFile *MyIni;
MyIni=new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));    panel->Left=MyIni->ReadInteger("PC","Left",0);
panel->Top=MyIni->ReadInteger("PC","Top",0);
panel->Width=MyIni->ReadInteger("PC","Width",0);
panel->Height=MyIni->ReadInteger("PC","Height",0);
delete MyIni;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
以下是我寫的小程式,可以下載來看看.↓
------
-----------------------
請多多指教啦!!^^
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-25 23:12:06 IP:140.135.xxx.xxx 未訂閱
kj68215您好: 我改了一下您的code(紅色部分),應該是您要的,希望您不要介意 並把專案上傳到下面連結供您參考 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=42714
void __fastcall TForm1::Button5Click(TObject *Sender)
{
 TIniFile *MyIni;
 MyIni=new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));
 TImage *PC_Image = new TImage(Form1);
 PC_Image->Parent = Form1;
 AnsiString AppPath  = ExtractFilePath(Application->ExeName);
 PC_Image->Width = 32;
 PC_Image->Height = 32;     PC_Image->Left=MyIni->ReadInteger("PC","Left",0);
 PC_Image->Top=MyIni->ReadInteger("PC","Top",0);
 PC_Image->Picture->LoadFromFile(AppPath "AddPc.bmp");
 PC_Image->Stretch = true;     PC_Image->OnMouseUp = &Image1MouseUp;
 PC_Image->OnMouseDown = &Image1MouseDown;
 PC_Image->OnMouseMove = &Image1MouseMove;     delete MyIni;
}
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
     //顯示出panel
     panel->Show();
     oldX = X;
     oldY = Y;
     //設定panel顯現狀態
     panel->Left = ((TImage*)Sender)->Left-2;
     panel->Top = ((TImage*)Sender)->Top-2;
     panel->Height = ((TImage*)Sender)->Height 15;
     panel->Width = ((TImage*)Sender)->Width 4;
     panel->Visible = true;         //當滑鼠左鍵按住Image1時,實際上是按住了panel
     ::SetCapture(panel->Handle);
     ((TImage*)Sender)->Parent = panel;
     ((TImage*)Sender)->Left = 2;
     ((TImage*)Sender)->Top = 2;
     //除了ImageL外,Label也一起顯示在新增的panel中
     /*
     TLabel *tmpLabel = ((TLabel*)FindComponent(((TImage*)Sender)->Name "Label"));
     tmpLabel->Parent=panel;
     tmpLabel->Left = 2;
     tmpLabel->Top = 2 ((TImage*)Sender)->Height;
     */
     Moving=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
     if (Moving)
     {
         Moving=false;
         //釋放panel的滑鼠捕捉
         ::ReleaseCapture();
         //隱藏panel在Image1下
         panel->Visible = false;
         ((TImage*)Sender)->Left = panel->Left;
         ((TImage*)Sender)->Top = panel->Top;
         ((TImage*)Sender)->Parent = this;
       /*
         TLabel *tmpLabel = ((TLabel*)FindComponent(((TImage*)Sender)->Name "Label"));
         tmpLabel->Parent=this;
         tmpLabel->Left = panel->Left;
         tmpLabel->Top = panel->Top ((TImage*)Sender)->Height;
         */
     }
}
//---------------------------------------------------------------------------
順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~ 發表人 -
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-12-27 11:53:15 IP:61.219.xxx.xxx 未訂閱
taishyang, 首先感謝您的回覆!< > 小弟修改之後,(暫時把>>、<>>! 但是跟我要的有一點點不同,就是說以>"最後一個所新增的<>>"而無法紀錄到所有新增的<>>。 小弟想要達到的功能,其實是如下這一張圖啦!↓< > < src="http://delphi.ktop.com.tw/download/upload\42788_Set_MAP.jpg"> Button1,屬性Caption:Add Button2,屬性Caption:Delete Button3,屬性Caption:Reset Button4,屬性Caption:Save Button5,屬性Caption:Load Button6,屬性Caption:Close 其中,Form1上所新增(Add)的3個小圖,其實就是3個panel。 小弟想要的是,要把這3個panel全都紀錄(Save)起來,當按下Load時可以把原先新增的panel數量、各個panel所在位置(起始、偏移)呈現出Save的紀錄,而不是只有紀錄到"最後新增的那一個panel" 關於這一點,小弟還想不出來該怎麼寫,想請問taishyang兄(或是其他大大)這該怎麼寫?! ----------------------- 請多多指教啦!!^^
------
-----------------------
請多多指教啦!!^^
hahalin
版主


發表:295
回覆:1698
積分:823
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-12-27 12:11:31 IP:211.76.xxx.xxx 未訂閱
check this http://delphi.ktop.com.tw/topic.php?TOPIC_ID=28591
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-12-30 18:23:51 IP:218.168.xxx.xxx 未訂閱
請問hahalin大大, 其實小弟對於Delphi完全不熟,不過看code部分,大致上可以瞭解一二. 關於您寫的Dephi版本,裡面的撰寫技巧可否適用於BCB呢?? 小弟滿欣賞您設計的風格,你是利用for迴圈去設計新增的台數.. 如此看來簡單、明瞭! 另外我比較不懂得地方,大概就是那個<>黃色長方形的方塊,如果用
------
-----------------------
請多多指教啦!!^^
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-12-30 18:53:15 IP:140.135.xxx.xxx 未訂閱
kj68215您好: 我想舉一反三應該就可以了,您可以規劃好ini檔達到您的目的 save時儲存所有電腦的資訊(數量.編號.位置等...) load時藉由ini檔來顯示所有的電腦 順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~
系統時間:2024-11-23 14:53:16
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!