九九乘法表,要怎麼除錯 |
尚未結案
|
_CCH_
一般會員 發表:10 回覆:29 積分:7 註冊:2004-04-20 發送簡訊給我 |
祇會用VC BC 我不會用DELPHI 7.0 ,最近才安裝好它,想學習一番。
請問一下,我將古早已前的Turbo Pascal 以前的學習範例,
一個九九乘法表的範例。拿到DELPHI 7.0 編譯。 CTRL F9 產生一個 EX1PAS.exe 檔案,
但是都會Runtime Error 105 at 004039d4 訊息。
這要怎麼改變,才能正常執行呢? { ** ********************************************************************** **}
{ ** ProgramName:: Ex1PAS.PAS 9x9 Multiplier Table **}
{ ** ********************************************************************** **}
Program ex1pas;
Var
i, j, k : integer;
Label ILab, JLab; Begin { ***** For Loop Routine ***** }
writeln('For Loop Routine');
k := 0;
for i := 1 to 9 do
Begin
for j := 1 to 9 do
Begin
k := i * j;
{ write(i:3, '*', j, '=', k:2); }
write(j:3, '*', i, '=', k:2);
End;
writeln;
End; { ***** While Loop Routine ***** }
writeln('While Loop Routine');
i := 1;
while i < 10 do
Begin
j := 1;
while j < 10 do
Begin
k := i*j;
{ write(i:3, '*', j, '=', k:2); }
write(j:3, '*', i, '=', k:2);
j := j 1;
End;
writeln;
i := i 1;
End; { ***** Pseudo While-Do Loop Routine ***** }
writeln('Pseudo While-Do Loop Routine');
i := 1;
ILab:
If i < 10 Then
Begin
j := 1;
JLab:
If j < 10 Then
Begin
k := i*j;
{ write(i:3, '*', j, '=', k:2); }
write(j:3, '*', i, '=', k:2);
j := j 1;
Goto JLab;
End;
writeln;
i := i 1;
Goto ILab;
End; { ***** Repeat-Until Loop Routine ***** }
writeln('Repeat-Until Loop Routine');
Begin
i := 1;
Repeat
j := 1;
Repeat
k := i*j;
{ write(i:3, '*', j, '=', k:2); }
write(j:3, '*', i, '=', k:2);
j := j 1;
Until j > 9; writeln;
i := i 1;
Until i > 9;
End; End. 秉燭夜遊,大塊文章。
文章是案頭之山水,山水是地上之文章。
------
秉燭夜遊,大塊文章。 文章是案頭之山水,山水是地上之文章。 |
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
_CCH_ 你好: 加入編譯指示(Console)試試看, Turbo Pascal 與 Object Pascal, 差一個字, 但是差很多喔.
{$APPTYPE CONSOLE} { ** ********************************************************************** **} { ** ProgramName:: Ex1PAS.PAS 9x9 Multiplier Table **} { ** ********************************************************************** **} Program ex1pas; Var ...發表人 - Mickey 於 2004/05/01 12:16:19 |
_CCH_
一般會員 發表:10 回覆:29 積分:7 註冊:2004-04-20 發送簡訊給我 |
|
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
可以運用 TextFile 傳接資料.
例如:
先在 Form 上放一個 Memo 及 Button, ButtonClick Event:
procedure TForm1.Button1Click(Sender: TObject); Var f : textfile; i, j, k : integer; Label ILab, JLab; Begin assignfile(f,'c:\dum.txt'); ReWrite(f); { ***** For Loop Routine ***** } writeln(f,'For Loop Routine'); k := 0; for i := 1 to 9 do Begin for j := 1 to 9 do Begin k := i * j; { write(i:3, '*', j, '=', k:2); } write(f, j:3, '*', i, '=', k:2); End; writeln(f); End; // 後續Code省略....記得 write / writeln 都要指定 "f" File CloseFile(f); memo1.lines.loadfromfile('c:\dum.txt'); End;發表人 - Mickey 於 2004/05/01 16:07:29 |
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
研究精進了一下, 連文字檔都可以不需要了.
參考看看:
< class="code">
function MyByPass(var t: TTextRec): Integer;
begin
Result := 0;
end; function MyTextOut(var t: TTextRec): Integer;
var
Dummy: array of char;
begin
if t.BufPos = 0 then
Result := 0
else
begin
if Form1<>nil then begin
SetLength(Dummy, t.BufPos);
move(t.BufPtr^ , Dummy[0] , t.BufPos);
Form1.Memo1.Lines.Text := Form1.Memo1.Lines.Text String(Dummy);
end;
Result := 0;
t.BufPos := 0;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
Var
f : textfile;
i, j, k : integer;
Label ILab, JLab;
Begin
assignfile(f,'');
TTextRec(f).InOutFunc := @MyTextOut;
TTextRec(f).OpenFunc := @MyByPass;
TTextRec(f).FlushFunc := @MyByPass;
TTextRec(f).CloseFunc := @MyByPass;
ReWrite(f);
{ ***** For Loop Routine ***** }
writeln(f, 'For Loop Routine');
k := 0;
for i := 1 to 9 do
Begin
for j := 1 to 9 do
Begin
k := i * j;
{ write(i:3, '*', j, '=', k:2); }
write(f, j:3, '*', i, '=', k:2);
End;
writeln(f);
End;
CloseFile(f);
End;
|
nnn0918k
一般會員 發表:12 回覆:33 積分:14 註冊:2003-05-12 發送簡訊給我 |
紅色部分
{ ** ********************************************************************** **} { ** ProgramName:: Ex1PAS.PAS 9x9 Multiplier Table **} { ** ********************************************************************** **} Program ex1pas; {$APPTYPE CONSOLE} uses SysUtils; Var i, j, k : integer; Label ILab, JLab; Begin火舞精靈 - 蘇 |
nnn0918k
一般會員 發表:12 回覆:33 積分:14 註冊:2003-05-12 發送簡訊給我 |
|
_CCH_
一般會員 發表:10 回覆:29 積分:7 註冊:2004-04-20 發送簡訊給我 |
>研究精進了一下, 連文字檔都可以不需要了.
>參考看看:
將整個敘述,編成Exp01.pas ,用DCC32 編譯,出現ERROR 訊息! ##################
function MyByPass(var t: TTextRec): Integer;
begin
Result := 0;
end; function MyTextOut(var t: TTextRec): Integer;
var
Dummy: array of char;
begin
if t.BufPos = 0 then
Result := 0
else
begin
if Form1<>nil then begin
SetLength(Dummy, t.BufPos);
move(t.BufPtr^ , Dummy[0] , t.BufPos);
Form1.Memo1.Lines.Text := Form1.Memo1.Lines.Text String(Dummy);
end;
Result := 0;
t.BufPos := 0;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
Var
f : textfile;
i, j, k : integer;
Label ILab, JLab;
Begin
assignfile(f,'');
TTextRec(f).InOutFunc := @MyTextOut;
TTextRec(f).OpenFunc := @MyByPass;
TTextRec(f).FlushFunc := @MyByPass;
TTextRec(f).CloseFunc := @MyByPass;
ReWrite(f);
{ ***** For Loop Routine ***** }
writeln(f, 'For Loop Routine');
k := 0;
for i := 1 to 9 do
Begin
for j := 1 to 9 do
Begin
k := i * j;
{ write(i:3, '*', j, '=', k:2); }
write(f, j:3, '*', i, '=', k:2);
End;
writeln(f);
End;
CloseFile(f);
End;
##################
我不太會用DELPHI 的。最近才開始玩著學。
能否進一步說明,謝謝版主大人。
最好打包成一個範例檔讓人觀看。謝謝啦。 [F:\_work_]dcc32 exp01.pas
Borland Delphi Version 14.0
Copyright (c) 1983,2002 Borland Software Corporation
exp01.pas(16) Error: Undeclared identifier: 'Form1'
exp01.pas(16) Error: Operator not applicable to this operand type
exp01.pas(19) Error: Missing operator or semicolon
exp01.pas(19) Error: Missing operator or semicolon
exp01.pas(19) Error: Missing operator or semicolon
exp01.pas(19) Error: Missing operator or semicolon
exp01.pas(19) Error: Incompatible types: 'String' and 'Text'
exp01.pas(26) Error: ';' expected but '.' found
exp01.pas(54)
exp01.pas(55) Error: Declaration expected but end of file found 秉燭夜遊,大塊文章。
文章是案頭之山水,山水是地上之文章。
------
秉燭夜遊,大塊文章。 文章是案頭之山水,山水是地上之文章。 |
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
您不是要轉視窗...
在 > class="code">
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} function MyByPass(var t: TTextRec): Integer;
begin
Result := 0;
end; function MyTextOut(var t: TTextRec): Integer;
var
Dummy: array of char;
begin
if t.BufPos = 0 then
Result := 0
else
begin
if Form1<>nil then begin
SetLength(Dummy, t.BufPos);
move(t.BufPtr^ , Dummy[0] , t.BufPos);
Form1.Memo1.Lines.Text := Form1.Memo1.Lines.Text String(Dummy);
end;
Result := 0;
t.BufPos := 0;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
Var
f : textfile;
i, j, k : integer;
Label ILab, JLab;
Begin
assignfile(f,'');
TTextRec(f).InOutFunc := @MyTextOut;
TTextRec(f).OpenFunc := @MyByPass;
TTextRec(f).FlushFunc := @MyByPass;
TTextRec(f).CloseFunc := @MyByPass;
ReWrite(f);
{ ***** For Loop Routine ***** }
writeln(f, 'For Loop Routine');
k := 0;
for i := 1 to 9 do
Begin
for j := 1 to 9 do
Begin
k := i * j;
{ write(i:3, '*', j, '=', k:2); }
write(f, j:3, '*', i, '=', k:2);
End;
writeln(f);
End;
CloseFile(f);
End; end.
|
_CCH_
一般會員 發表:10 回覆:29 積分:7 註冊:2004-04-20 發送簡訊給我 |
|
hahalin
版主 發表:295 回覆:1698 積分:823 註冊:2002-04-14 發送簡訊給我 |
|
_CCH_
一般會員 發表:10 回覆:29 積分:7 註冊:2004-04-20 發送簡訊給我 |
對了,怎麼製作FORM1 ,就是此程式所需的DFM 檔。
我祇知道寫C 或是C++ 程式會用到 *.rc *.res 。 修改過的程式有了,尚缺DFM 檔。
能否補個DFM 檔,醬子就通通OK了。
Unit 全文如下: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function MyByPass(var t: TTextRec): Integer; begin Result := 0; end; function MyTextOut(var t: TTextRec): Integer; var Dummy: array of char; begin if t.BufPos = 0 then Result := 0 else begin if Form1<>nil then begin SetLength(Dummy, t.BufPos); move(t.BufPtr^ , Dummy[0] , t.BufPos); Form1.Memo1.Lines.Text := Form1.Memo1.Lines.Text String(Dummy); end; Result := 0; t.BufPos := 0; end; end; procedure TForm1.Button1Click(Sender: TObject); Var f : textfile; i, j, k : integer; Label ILab, JLab; Begin assignfile(f,''); TTextRec(f).InOutFunc := @MyTextOut; TTextRec(f).OpenFunc := @MyByPass; TTextRec(f).FlushFunc := @MyByPass; TTextRec(f).CloseFunc := @MyByPass; ReWrite(f); { ***** For Loop Routine ***** } writeln(f, 'For Loop Routine'); k := 0; for i := 1 to 9 do Begin for j := 1 to 9 do Begin k := i * j; { write(i:3, '*', j, '=', k:2); } write(f, j:3, '*', i, '=', k:2); End; writeln(f); End; CloseFile(f); End; end.秉燭夜遊,大塊文章。 文章是案頭之山水,山水是地上之文章。
------
秉燭夜遊,大塊文章。 文章是案頭之山水,山水是地上之文章。 |
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
引言: 修改過的程式有了,尚缺DFM 檔。 能否補個DFM 檔,醬子就通通OK了。Delphi 開發環境一執行起來, 就有一個 Default 的 Unit1.dfm 與 Unit1.Pas了.....這樣貼 Code....真是浪費版面..... object Form1: TForm1 Left = 192 Top = 107 Width = 696 Height = 480 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object Memo1: TMemo Left = 0 Top = 0 Width = 688 Height = 412 Align = alClient Lines.Strings = ( 'Memo1') TabOrder = 0 end object Panel1: TPanel Left = 0 Top = 412 Width = 688 Height = 41 Align = alBottom Caption = 'Panel1' TabOrder = 1 object Button1: TButton Left = 496 Top = 8 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 0 end end end |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |