1
제품 정보 (브랜드 이름, 내용, 질량 및 재고량)를 입력하고 표시하는 프로그램을 만들어야합니다.입력 상자가 순서대로 표시되지 않는 이유는 무엇입니까?
문제점 :이 코드 조각의 입력란은 코드가 순서대로 표시되도록 작성되었지만 순서대로 표시되지 않습니다. 입력란의 순서는 "내용", "질량", "재고", "브랜드 이름"이며 실제로 "브랜드 이름", "내용", "질량", "재고"입니다. 입력 상자의 캡션). 따라서이 갈 것입니다 어디에 데이터가 간다 - 모든
:
StrObj := TProducts.Create(Inputbox('Brand name', 'Input the brand name', ''),Inputbox('Contents', 'Input the contents', ''), StrToInt(Inputbox('Mass', 'Input the mass', '')), StrToInt(Inputbox('Stock', 'Input the number in stock', '')));
참고 :
이 소스 (프로그램의 나머지 부분에 대한 아래로 스크롤을) 할 수 있다고 생각 나두 입력 상자의 순서는 프로그램에 전혀 영향을 미치지 않습니다. 입력 상자를 순서대로 표시하는 방법이 있는지 알고 싶습니다.- 이것은 할당이지만 입력 상자의 순서는 점수를 계산하지 않습니다.
전체 코드 :
응용 프로그램 :
unit TProducts_U;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, TProducts_class;
type
TForm1 = class(TForm)
btnResult: TButton;
redOut: TRichEdit;
procedure btnResultClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnResultClick(Sender: TObject);
var StrObj : TProducts;
begin
StrObj := TProducts.Create(Inputbox('Brand name', 'Input the brand name', ''),Inputbox('Contents', 'Input the contents', ''), StrToInt(Inputbox('Mass', 'Input the mass', '')), StrToInt(Inputbox('Stock', 'Input the number in stock', '')));
redOut.Lines.Add(StrObj.toString);
end;
end.
내 클래스 :
unit TProducts_class;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Math;
type
TProducts = class
private
fBname, fContents : string;
fMass, fNum : integer;
public
Constructor Create; overload;
Constructor Create(Bname, contents : string; mass, num : integer); overload;
Function toString : string;
end;
implementation
{ TProducts }
constructor TProducts.Create;
begin
fBname := '';
fContents := '';
fMass := 0;
fNum := 0;
end;
constructor TProducts.Create(Bname, contents: string; mass, num: integer);
begin
fBname := Bname;
fContents := contents;
fMass := mass;
fNum := num;
end;
function TProducts.toString: string;
begin
result := 'Brand Name is : ' + fBname + #13 +
'Contents is : ' + fContents + #13 +
'Mass is : ' + IntToStr(fMass) + #13 +
'We have ' + IntToStr(fNum) + ' in stock';
end;
end.
잘못된되지 않는 게다가 그 * 훨씬 * 더 읽기. :-) –
대화 상자 닫기 버튼 (빨간색 X) 등을 누르는 사용자가 준비해야합니다. –