2013-12-09 31 views
0

我有一個備忘錄字段,可以顯示如何使用我的GUI的說明。我爲備忘錄啓用了水平和垂直滾動條。兩個滾動條均顯示爲詳細說明,並且在垂直和水平方向都超過了框架。但是,垂直滾動條始終位於底部,所以除非用戶向上滾動,否則他將在開始時錯過指示。水平滾動條正確在左側。我需要在Object Inspector中更改備忘錄的某些屬性以確保垂直欄位於頂部,以便用戶可以從頭閱讀說明?垂直滾動條總是在底部 - Delphi

我已將說明保存爲名爲Instructions的字符串。我這個字符串複製到該備忘錄由下面的代碼的方式:

procedure TfrmHSR.mmuDispInstructionsClick(Sender: TObject); 
//display instructions in Memo field 
var 
    DispText: string; 
begin 
    Memo1.Clear; 
    DispText := Wraptext(Instructions, 125); 
    Memo1.Lines.Add(DispText); 
    mmuDisplayClear.Enabled := True; 
    mmuFileSave.Enabled := False; 
    //if input file created and opened, allow display of input data 
    if Assigned(InputFile) then //if TStringList has been created 
    begin 
     if (InputFile.Count > 0) then mmuDispData.Enabled := True 
     else mmuDispData.Enabled := False; 
    end 
    else mmuDispData.Enabled := False; 

    //if results available, allow display 
    if Assigned(OutputFile) then //if TStringList has been created 
    begin 
     if (OutputFile.Count > 0) then mmuDispResults.Enabled := True 
     else mmuDispResults.Enabled := False; 
    end 
    else mmuDispResults.Enabled := False; 
    mmuDispInstructions.Enabled := False; 
end; 
+0

你是如何填補備忘錄?我無法在快速測試應用程序中複製此內容。 –

+0

如果你要將插入符號保留在左上角,那麼我不認爲有明確的設置可以這樣做。但是,您可以調用此'Memo.Perform(EM_SETSEL,0,0); Memo.Perform(EM_SCROLLCARET,0,0);'添加行後。 – TLama

+0

當用戶點擊「顯示」菜單中的「顯示指令」子菜單選項(可以顯示其他內容)時,我將這些指令保存爲長字符串(帶有大量換行符)也在菜單字段中,例如上傳的數據)。 – Serge

回答

2

爲您遇到的問題最簡單的解決方法是根本不使用TMemo.ClearTMemo.Add,而是直接分配給Text財產作爲整個。 (你的所有文本一次,所以根本不需要使用Add。)

我冒昧地對代碼進行了一些其他細微的更改,您可能也會發現有幫助;國際海事組織閱讀起來有點清晰,但稍短。 :-)

//display instructions in Memo field 
procedure TfrmHSR.mmuDispInstructionsClick(Sender: TObject); 
var 
    DispText: string; 
begin 
    DispText := Wraptext(Instructions, 125); 
    Memo1.Text := DispText; 

    mmuDisplayClear.Enabled := True; 
    mmuFileSave.Enabled := False; 

    //if input file created and opened, allow display of input data 
    //if TStringList has been created 
    mnuDispData.Enabled := Assigned(InputFile) and (InputFile.Count > 0); 

    //if results available, allow display 
    //if TStringList has been created 
    mnuDispResults.Enabled := Assigned(OutputFile) and (OutputCount > 0); 
    mmuDispInstructions.Enabled := False; 
end; 
+0

謝謝。你的代碼肯定比較短。我也不知道你可以用這種方式使用賦值:'mnuDispData.Enabled:=賦值(InputFile)和(InputFile.Count> 0); mmuDispInstructions.Enabled:=假;'而不是更笨重'if'語句:'如果已分配(INPUTFILE)然後 開始 如果(InputFile.Count> 0),則mmuDispData.Enabled:=真否則 mmuDispData.Enabled:=假; end else mmuDispData.Enabled:= False;'。但是如果輸入文件沒有被創建和/或什麼都沒有被添加到OutputFile會發生什麼?這項任務做了什麼? – Serge

+1

默認情況下,Delphi會對布爾評估進行短路,這意味着如果第一個條件爲false,則第二個條件永遠不會執行。因此,就'InputFile'而言,例如,如果'Assigned'返回false,則'InputFile.Count - 1'永遠不會執行。如果'Assigned'爲真,則評估InputFile.Count。如果* both *爲真,那麼整個表達式返回true(因爲'和'),並且它被分配給菜單項的'Enabled'屬性。如果* * *返回false,則整個表達式返回'false'(同樣,由於'和'),並且它被分配給'Enabled'。 –

+0

不錯。感謝您的解釋。我希望有一天能像個程序員一樣思考! :0(但是這個論壇是一個巨大的幫助!再次感謝。 – Serge

0
//if you need to add the lines using lines.add() you can use this... 

    procedure TForm2.Button1Click(Sender: TObject); 
    var 
     I: Integer; 
    begin   
     for I := 0 to 1000 do 
     begin 
     memo1.Lines.add('line ' + intToStr(i)); 
     end; 
    SendMessage(Memo1.Handle, EM_SETSEL, 0, 0); 
    SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0);   
    end;