//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: //
TMemo *Memo1;
TButton *Button1;
void __fastcall Memo1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
private: //
int m_lineNo;
public: //
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
m_lineNo = 0;
Memo1->Clear();
}
//---------------------------------------------------------------------------
// http://stackoverflow.com/questions/14189171/removing-last-blank-line-in-memo/14189378#14189378
void __fastcall TForm1::Memo1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if (Key == VK_F9) {
String str = String().sprintf(L"%03d: ", m_lineNo);
// Memo1->Lines->Add(str);
// instead, use follow
Memo1->SelStart = Memo1->GetTextLen();
Memo1->SelLength = 0;
Memo1->SelText = str;
m_lineNo++;
}
}
//---------------------------------------------------------------------------