線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2578
推到 Plurk!
推到 Facebook!

九九乘法表,要怎麼除錯

尚未結案
_CCH_
一般會員


發表:10
回覆:29
積分:7
註冊:2004-04-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-01 11:58:35 IP:211.75.xxx.xxx 未訂閱
祇會用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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-01 12:15:24 IP:218.32.xxx.xxx 未訂閱
_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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-01 12:20:36 IP:211.75.xxx.xxx 未訂閱
謝謝提點! 好的,我再試試看。 對了,還想再問一個問題。 CONSOLE 命令列的環境,都還要開啟Dos BOX 。 就是如何將,古早DOS 寫的 Pascal 程式轉成視窗執行模式。 秉燭夜遊,大塊文章。 文章是案頭之山水,山水是地上之文章。
------
秉燭夜遊,大塊文章。
文章是案頭之山水,山水是地上之文章。
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-05-01 16:04:23 IP:218.32.xxx.xxx 未訂閱
可以運用 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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-05-01 16:39:17 IP:218.32.xxx.xxx 未訂閱
研究精進了一下, 連文字檔都可以不需要了. 參考看看: < 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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-05-01 19:32:03 IP:61.216.xxx.xxx 未訂閱
紅色部分    
{ ** ********************************************************************** **}
{ ** 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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-05-01 19:33:28 IP:61.216.xxx.xxx 未訂閱
證實.. 加這行就行了 {$APPTYPE CONSOLE} 火舞精靈 - 蘇
_CCH_
一般會員


發表:10
回覆:29
積分:7
註冊:2004-04-20

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-05-02 16:10:18 IP:211.75.xxx.xxx 未訂閱
>研究精進了一下, 連文字檔都可以不需要了. >參考看看: 將整個敘述,編成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

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-05-03 08:29:42 IP:218.163.xxx.xxx 未訂閱
您不是要轉視窗... 在 > 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

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-05-03 08:49:56 IP:211.22.xxx.xxx 未訂閱
DELPHI大外行的我又來了。 嘻嘻。 再問請教一下,為何我貼文的程式碼,在版面都變成向左排列不能『縮排』。 討論版怎麼貼文才能保持CODE 的縮排,醬子眼睛看得才舒服。 秉燭夜遊,大塊文章。 文章是案頭之山水,山水是地上之文章。
------
秉燭夜遊,大塊文章。
文章是案頭之山水,山水是地上之文章。
hahalin
版主


發表:295
回覆:1698
積分:823
註冊:2002-04-14

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-05-03 09:24:45 IP:210.243.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=7326 發表人 - hahalin 於 2004/05/03 09:28:47
_CCH_
一般會員


發表:10
回覆:29
積分:7
註冊:2004-04-20

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-05-03 09:50:42 IP:211.22.xxx.xxx 未訂閱
對了,怎麼製作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

發送簡訊給我
#13 引用回覆 回覆 發表時間:2004-05-03 11:48:17 IP:218.163.xxx.xxx 未訂閱
引言: 修改過的程式有了,尚缺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
系統時間:2024-05-15 16:00:44
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!