0

Есть код

 for j := 0 to mForm.ComponentCount - 1 do
    if mForm.Components[j] is TableFormInfo then
      //try
        //table := nil;
        //tempFmtable := nil;
        //tForm := nil;

        tForm := mForm.Components[j] as TableFormInfo;

        table := TTableSpec(DBSchema.Tables.FindComponent(tForm.Table));
        tempFmtable := TfmTableData.Create(MainWindow);
        tempFmtable.Name := tForm.Name;
        tempFmtable.tname := tForm.Table;
        //tempFmtable.Caption := Utf8ToAnsi(table.Description);
        tempFmtable.Left := tForm.LeftValue;
        tempFmtable.Top := tForm.TopValue;
        tempFmtable.Height := tForm.HeightValue;
        tempFmtable.Width := tForm.WidthValue;

        tempFmTable.IBQuery1.SQL.Clear;
        tempFmtable.IBQuery1.SQL.Add('select * from ' + table.Name);
        tempFmtable.IBQuery1.Open;
        tempFmtable.DragKind:=dkDock;
        tempFmtable.DragMode:=dmAutomatic;

        i := 0;
        querystr:='select ';
        while i <= tForm.ComponentCount - 1 do
          begin
          if tForm.Components[i] is TableFieldInfo then
          begin
            //querystr:='select ';
            //field := nil;
            //tempFmtable.Show;
            field := tForm.Components[i] as TableFieldInfo;
            tempFmtable.Caption:=tForm.Caption;
            tempFmtable.DBGrid1.Columns[i].FieldName := field.FieldNameValue;
            tempFmtable.DBGrid1.Columns[i].Title.Caption := field.DescriptionValue;
            tempFmtable.DBGrid1.Columns[i].Index := field.IndexValue;
            tempFmtable.DBGrid1.Columns[i].Visible := field.VisibleValue;
            tempFmtable.DBGrid1.Columns[i].Width:=field.WidthValue;
            //tempFmtable.CheckListBox1.Items.Add(field.Description);
            //tempFmtable.CheckListBox1.Checked[i] := field.Visible;
            //tempFmtable.Show;
             if field.VisibleValue  then querystr:=querystr+ConvertNameField(field.FieldNameValue)+', ';
          end;
            //inc(i);
          if tForm.Components[i] is SettingsFormInfo then
            begin
              //sForm:=nil;
              sForm:=tForm.Components[i] as SettingsFormInfo;
              tempsettings := TfmSettings.Create(tempFmtable);
              tempsettings.Caption:=sForm.Caption;
              //tempsettings := TfmSettings.Create(tempFmtable);
              tempsettings.Name := sForm.Name;
              tempsettings.Left := sForm.LeftValue;
              tempsettings.Top := sForm.TopValue;
              tempsettings.Height := sForm.HeightValue;
              tempsettings.Width := sForm.WidthValue;
              tempSettings.CheckListBox1.Clear;
              //for k:=0 to sForm.ComponentCount-1 do
              k:=0;
              while k<=sForm.ComponentCount-1 do
                begin
                  if sForm.Components[k] is ItemCheckListBoxInfo then
                    begin
                      //item:=nil;
                      item:=sForm.Components[k] as ItemCheckListBoxInfo;
                      tempsettings.CheckListBox1.Items.Add(item.TextValue);
                      tempsettings.CheckListBox1.Checked[item.IndexValue]:=item.CheckedValue
                    end;
                  if sForm.Components[k] is LabelInfo then
                    begin
                      //labelobj:=nil;
                      labelobj:=sForm.Components[k] as LabelInfo;
                      tempsettings.Label1.Caption:=labelobj.CaptionValue;
                    end;
                  if sForm.Components[k] is EditInfo then
                    begin
                      //edit:=nil;
                      edit:=sForm.Components[k] as EditInfo;
                      TEdit(tempsettings.FindComponent(edit.Name)).Text:=edit.TextValue;
                    end;
                    inc(k);
                end;
             if ((tForm.Components[i] is SettingsFormInfo) and (i=tForm.ComponentCount-1) and (k=sForm.ComponentCount)) then tempsettings.Show;
            end;
             //inc(i);
             //if ((tForm.Components[i] is SettingsFormInfo) and (i=tForm.ComponentCount-1) and (k=sForm.ComponentCount)) then tempsettings.Show;
             inc(i);
          end;

        {for i := 0 to table.Fields.ComponentCount - 1 do
        begin
          descr := Utf8ToAnsi(((table.Fields.Components[i]) as TFieldSpec).Description);
          tempFmtable.CheckListBox1.Items.Add(descr);
          tempFmtable.DBGrid1.Columns[i].Title.Caption := descr;
          tempFmtable.CheckListBox1.Checked[i] := true;
        end; }

        Delete(querystr, Length(querystr)-1, 1);
        querystr:=querystr+'from '+table.Name;
        tempFmTable.IBQuery1.SQL.Clear;
        tempFmtable.IBQuery1.SQL.Add(querystr);
        tempFmtable.IBQuery1.Open;
        for s := 0 to tForm.ComponentCount-1 do
          begin
            if tForm.Components[s] is TableFieldInfo then
              begin
                //field := nil;
                //tempFmtable.Show;
                field := tForm.Components[s] as TableFieldInfo;
                if field.VisibleValue then
                   begin
                     for t := 0 to tempFmtable.DBGrid1.Columns.Count-1 do
                       begin
                       if ((tempFmTable.DBGrid1.Columns[t].Title.Caption=field.DescriptionValue) and (tempFmtable.DBGrid1.Columns[t].FieldName=field.FieldNameValue)) then
                           tempFmTable.DBGrid1.Columns[t].Width:=field.WidthValue;
                       end;
                   end;
              end;
          end;
        tempFmtable.Show;

восстанавливающий форму с помощью десериализации. Хочу отметить, что перед использованием переменной tForm в строке

table := TTableSpec(DBSchema.Tables.FindComponent(tForm.Table));

она инициализируется в предыдущей строке

tForm := mForm.Components[j] as TableFormInfo;

Но несмотря на это при сборке возникает предупреждение

[dcc32 Warning] SerAndDeser.pas(298): W1036 Variable 'tForm' might not have been initialized

Почему? Как избавиться от этого предупреждения, не потеряв функциональности приложения?

1 ответ 1

1

tForm := mForm.Components[0] as TableFormInfo;

Где не будь в начале инициализируй, да и пытайся сам разобраться, типичные же предупреждения.

7
  • а возникает потому что есть вариант что цикл не пройдет, теоретически
    – Rsecomua
    19 дек 2012 в 14:36
  • @savro я знаю точно из процесса создания приложения, что компоненты типа TableFormInfo точно есть в контейнере mForm. Но в таком случае раз нужна проверка на is, то от предупреждения невозможно избавиться?
    – ivan89
    19 дек 2012 в 14:42
  • То что ты знаешь компилятор не знает по этому и предупреждает.
    – Rsecomua
    19 дек 2012 в 14:47
  • @savro так от этого предупреждения избавиться нельзя?
    – ivan89
    19 дек 2012 в 14:51
  • я же написал решение, напиши в начале кода. на функционал не повлияет, а вот компилятор успокоит
    – Rsecomua
    19 дек 2012 в 14:54

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.