times2.cpp

来自「a program that generates a pulse-width m」· C++ 代码 · 共 48 行

CPP
48
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <stdlib.h>
#pragma hdrstop

#include "Times2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
void TForm1::DoMult(void)
{
char buf[100];
double value;

Edit1->GetTextBuf(buf,100);
sscanf(buf,"%lf",&value);
sprintf(buf,"%lg",2.0 * value);
Edit2->SetTextBuf(buf);
}


//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
DoMult();  // Make sure initial values are correct
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if(Key == '\r')DoMult();  // Update if user presses ENTER
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Exit(TObject *Sender)
{
DoMult();  // Update on loss of focus        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
exit(0);  // End execution        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?