( ゚Д゚)ノ Delギコ猫のプログラミング相談室

このエントリーをはてなブックマークに追加
262Delギコ
  ∧∧   / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
 (,,゚Д゚) < >>196 のインターフェースはダメだった
Π ̄ ̄ ̄| \
|つ ダメ ()    ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
| |___.|
  ∪∪
**************************************
unit StringsInt;
interface
uses Classes;
type
 IStringsInt = interface
  ['{ヒミチュ}']
  procedure SetStringItems(Strings: TStrings);
 end;
const
 IStringsInt_IID: TGUID =
  '{ヒロミチュ}';
implementation
end.
**************************************
unit UseInterface;
interface
 type
  TUseInterfaceObject = class(TObject, IUnknown)
 private
 protected
  function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
  function _AddRef: Integer; stdcall;
  function _Release: Integer; stdcall;
 public
 end;
implementation
{ TUseInterfaceObject }
function TUseInterfaceObject._AddRef: Integer;
begin
 Result := -1;
end;
function TUseInterfaceObject._Release: Integer;
begin
 Result := -1;
end;
function TUseInterfaceObject.QueryInterface(const IID: TGUID;
 out Obj): HResult;
const
 E_NOINTERFACE = Hresult($80004002);
begin
 if GetInterface(IID, Obj) then
  Result := 0
 else
  Result := E_NOINTERFACE;
end;
end.
263Delギコ:2001/08/14(火) 19:48
**************************************
uses
 UseInterface, StringsInt追加

 TStringStore = class(TUseInterfaceObject, IStringsInt)
 private
  FStrings: TStrings;
  procedure SetStrings(const Value: TStrings);
 public
  constructor Create;
  destructor Destroy; override;
  procedure SetStringItems(Items: TStrings);
  property Strings: TStrings read FStrings write SetStrings;
 end;
{ TStringStore }
constructor TStringStore.Create;
begin
 FStrings := TStringList.Create;
end;
destructor TStringStore.Destroy;
begin
 FStrings.Free;
 inherited;
end;
procedure TStringStore.SetStringItems(Items: TStrings);
begin
 FStrings.Assign(Items);
end;
procedure TStringStore.SetStrings(const Value: TStrings);
begin
 FStrings.Assign(Value);
end;
procedure SetScreenFontNames(Obj: TObject);
var i: IStringsInt;
begin
 Obj.GetInterface(IStringsInt_IID, i);
 if i <> Nil then
  i.SetStringItems(Screen.Fonts);
end;//ここでiがNilになってしまう。なぜ?

procedure TForm1.Button2Click(Sender: TObject);
var StringStore1: TStringStore; i: Integer;
begin
 StringStore1 := TStringStore.Create;
 try
  SetScreenFontNames(StringStore1);

  for i := 0 to StringStore1.Strings.Count-1 do  begin
   Memo1.Lines.Add(StringStore1.Strings[i]);
  end;
 finally
  StringStore1.Free;
 end;
end;
 ∧ ∧      / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
 (,,゚Д゚)  <  なぜ、動作せん!?いやがらせか!
  | つ[|lllll]). \_________
〜|   |
  ∪∪