微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在处理中运行时,我的草图不会显示任何内容

如何解决在处理中运行时,我的草图不会显示任何内容

我对处理完全陌生,我想通过创建一个绘制矩形的简单草图来对其进行测试,但是,当我运行该草图时,会弹出一个没有任何内容的窗口。我尝试填充它,在其上勾勒出轮廓,以及其他各种东西,什么都没发生。我认为这不是代码问题,而是应用程序本身的问题,我不确定如何解决。我正在Windows上处理3.5.4。

代码

uses
System.Win.ComObj,Excel2010
...

procedure GerarExcel(ADBGrid: TDBGrid; AQuery: TFDQuery);
var
  Excel: Variant;
  linha,coluna,I,X: Integer;
begin
  {Here you create the Excel Application Object}
  Excel := CreateOleObject('Excel.Application');
  {If you want to open the excel you can set this line to True.
  In case you want to save directly without user intervention you can set to False.}
  Excel.Visible :=True;
  Excel.Workbooks.Add;

  {In this case
  Titles begin on the (4) line and different columns (1-7)}
  Excel.WorkBooks[1].Sheets[1].Cells[4,1].Interior.ColorIndex := 55;
  Excel.WorkBooks[1].Sheets[1].Cells[4,1].Font.ColorIndex := 2;
  Excel.WorkBooks[1].Sheets[1].Cells[4,1].Font.Bold := True;
  Excel.WorkBooks[1].Sheets[1].Cells[4,1].font.size := 10;
  Excel.WorkBooks[1].Sheets[1].Cells[4,1] := 'Your Title 2';
  Excel.WorkBooks[1].Sheets[1].Cells[4,1].ColumnWidth := 15;
  
  ...

  Excel.WorkBooks[1].Sheets[1].Cells[4,7].Interior.ColorIndex := 55;
  Excel.WorkBooks[1].Sheets[1].Cells[4,7].Font.ColorIndex := 2;
  Excel.WorkBooks[1].Sheets[1].Cells[4,7].Font.Bold := True;
  Excel.WorkBooks[1].Sheets[1].Cells[4,7].font.size := 10;
  Excel.WorkBooks[1].Sheets[1].Cells[4,7] := 'Your Title 7';
  Excel.WorkBooks[1].Sheets[1].Cells[4,7].ColumnWidth := 17;
  Excel.WorkBooks[1].Sheets[1].Cells[4,7].HorizontalAlignment := 4;
  Excel.WorkBooks[1].Sheets[1].Cells[4,7].verticalAlignment   := 1;

  I := 1;
  {In case you want to loop through a TClientDateSet to fill in the cells}
  with AQuery do
  begin
    First;
    while not Eof do
    begin
      {To change to a specific format}
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,1].NumberFormat := 'dd/mm/aaaa';
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,1] := FieldByName(C_DATA).AsDateTime;
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,2] := FieldByName(C_CONTA_CREDITO).Asstring;
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,3] := FieldByName(C_CONTA_DEBITO).Asstring;
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,4].NumberFormat := 'R$#.##0,00';
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,4] := FieldByName(C_VALOR).Asstring;
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,5] := FieldByName(C_DESCRICAO).Asstring;
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,6] := FieldByName(C_NOME).Asstring;
      Excel.WorkBooks[1].Sheets[1].Cells[I + 4,7] := FieldByName(C_NOME_MOVIMENTO).Asstring;
      Inc(I);

      Next;
    end;
  end;

  {All these variables configure the for landscape printing.}
  Excel.ActiveSheet.PageSetup.RightFooter := 'Página &P de &N';
  Excel.ActiveSheet.PageSetup.LeftFooter := '&D';
  Excel.ActiveSheet.PageSetup.Orientation := 2;
  Excel.ActiveSheet.PageSetup.PaperSize := xlPaperA4;
  Excel.ActiveSheet.PageSetup.FitToPagesTall := False;
  Excel.ActiveSheet.PageSetup.Zoom := False;
  Excel.ActiveSheet.PageSetup.FitToPagesWide := 1;

  {If you want the user to see the excel being opened and save it wherever the user wants
  You are done here.}

  {Save the file automatically
  If you want the user to NOT see the excel being opened and save the file in a specific folder automatically
  In the beginning you need to set Visible := False and then these lines}
  FilePath := 'C:\...\my_excel_file.xlsx';
  if FileExists(FilePath) then
    DeleteFile(FilePath);
  Excel.WorkBooks[1].Sheets[1].SaveAs(FilePath);

  Excel.Quit;
end;

预期输出:屏幕上将显示一个正方形。

输出:什么都没有显示

class Sketch {
  void setup() {
    size(100,100);
  }
  
  void draw() {
    rect(50,50,25,25);
  }
}

解决方法

显而易见的事情(如果我没有正确回答你的问题,不要伤害我):

draw()setup()已经在处理中。实际上,您写到类中的那些内容不会自动执行,因为Processing会查找自己的方法。这就是为什么你得到这个:

No square here

顺便说一下,这与您运行一个空草图完全相同。

要解决此问题,只需将draw()setup()从类中删除,然后Processing将查找并运行它们:

void setup() {
  size(100,100);
}

void draw() {
  rect(50,50,25,25);
}

Out of the class

玩得开心!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。